move selected files to predefined destination

This should be simple for our scripters (though not for me):

A script to move selected files to a different location within DEVONthink Pro Office (different group, maybe in a different database). I would like to have the destination hardcoded in that script, which I would invoke from the toolbar or via LaunchBar.

I’m aware of this excellent script from Rob aka houthakker, but I have some groups I have to file files to very often, so a ‘direct’ script would be faster. I’m also aware of the favorites in the side panel and the hud-panel for groups and tags, which are great for quick sorting, but I’d love to avoid the mouse-work.

Thanks for listening,
Bernd

There are other examples of this, but here’s one:

[size=85]Updated to reflect comments downstream in this thread[/size]

tell application id "DNtp"
		try
			set theDatabase to open database "<database path (to .dtBase2 package) in file system>"
			
			if selection is {} then error "Please select a single record"
			set theRecord to the selection as list
			
			set theLocation to create location "</path/to/destination>" in theDatabase
			
			repeat with thisItem in theRecord
				set theResult to move record thisItem to theLocation
			end repeat
			
		on error error_message number error_number
			if the error_number is not -128 then
				try
					display alert "DEVONthink Pro" message error_message as warning
				on error number error_number
					if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
				end try
			end if
		end try
	end tell

Replace the placeholders in theDatabase and theLocation, and there you are.

This is intended for a single record only – selecting multiple items will move only the first item in the selection, though the script can easily be modified to do otherwise by changing


set theRecord to the first item of (the selection as list)

to


set theRecord to the selection

Yeah! Works like charm, thank you!

I did so and with otherwise the same parameters - I got the paths all right as the script for a single file works fine - this does not work here with multiple files selected.
This is what I get back from the AppleScript Editor:

tell application "DEVONthink Pro"
	open database "/Users/me/Documents/DEVONthinkPro/datenbanken/Studio.dtBase2"
		--> database id 2
	get selection
		--> {content id 211204 of database id 2, content id 211212 of database id 2}
	get selection
		--> {content id 211204 of database id 2, content id 211212 of database id 2}
	create location "/UVK-Preise 2013" in database id 2
		--> parent id 219634 of database id 2
	move current application record {content id 211204 of database id 2, content id 211212 of database id 2} to parent id 219634 of database id 2
		--> missing value
end tell
Result:
missing value

Well, that would be because I posted a non-working version :open_mouth:

Upstream in my first post I re-placed the old version with one that actually works :unamused:

Technically, the problem is that the selection and hence theRecord is a list of references, whereas the move record command works only with references. To solve this problem construct a loop, e.g.:


repeat with thisItem in theRecord
 move record thisItem to theLocation
end repeat

@arnow, please read the thread. I said I mistakenly posted a non-working version and then posted the fix upstream in my original posting.

Yeah! Perfect, this works and it does regardless whether I have a single selection or a multiple selection, which of course is the universal solution for me.

Thank you so much, korm, and thank you, Arno, too! Much appreciated.

Bernd

I did. Of course I did. I guess you posted a correction while I was writing my reply. :slight_smile: