Move items with the keyboard between databases (re-imagined)

Sometimes we want to move items from one database to another using the keyboard. Here is a re-imagining of the original scripts found here, now all accomplished with a single script.

This version of solution will prompt you to select a destination using the Group Selector panel, which can be navigated using the keyboard. In that panel, press up/down arrows to move between databases or groups and the left/right arrows to expand/collapse groups in the display. (If you take your hands off the keyboard, the Group Selector can also be used to create a new destination group). After navigating the Group Selector with the arrow keys, press Return to complete the action.

The script records what it has done to DEVONthinkā€™s Log (see Window > Log).

Save this script with the name Move___Cmd-Ctrl-M (for ā€œsuper moveā€) in the folder ~/Library/Application Support/DEVONthink Pro 2/Scripts. (Note, that is three underscores in the name.)

(* 
Move the selected record(s) to a destination
that was selectected from the Group Selector panel
20140112.1
*)

try
	tell application id "com.devon-technologies.thinkpro2"
		
		set theDatabase to current database
		set theSelection to selection
		if theSelection is {} then error "Please select something"
		
		set fromPath to (the location of item 1 of theSelection) & (the name of item 1 of theSelection)
		set fromDatabase to the name of theDatabase
		
		set theDestination to (display group selector "Select a Destination")
		if theDestination is {} then error "We had a problem choosing the destination"
		
		set toPath to the location of theDestination
		set toDatabase to the name of the database of theDestination
		
		repeat with thisItem in theSelection
			move record thisItem to theDestination
		end repeat
		
		-- Post the result to the Log
		set movedFrom to "Moved from: " & fromPath & " in " & fromDatabase
		set movedTo to " -- Moved to: " & toPath & " in " & toDatabase
		set theLogEvent to log message (movedFrom & movedTo) info "Mover Script"
		
	end tell
	
on error error_message number error_number
	if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	
end try
1 Like

Very nicely done korm, as the script works well. One question on the command-control-s shortcut-donā€™t you have a conflict with the See Also & Classify command?

Ooops. :confused:

Yes. And the script should be in the Scripts subfolder. Iā€™ve adjusted the advice above to suggest Move___Cmd-Ctrl-M. Of course, any non-conflicting shortcut can be used by combing terms using ā€œCmdā€, ā€œShiftā€, ā€œAltā€, or ā€œCtrlā€ for āŒ˜, ā‡§, āŒ„, and āŒƒ, respectively. Separate the terms with hyphens and precede the keyboard shortcut string with three underscores. Or, one could install the script in Keyboard Maestro, etc.

A nice byproduct of this script is that the Group Selector remembers its last selected group. So, if you are reorganizing and consolidating documents or groups from multiple locations into one destination ā€“ even if within the same database ā€“ then you can quickly do this by pressing return on the Group Selector without doing navigation.

And recall, too, that in all views and panels DEVONthink supports Macā€™s type-ahead feature: by typing the first few characters of an item in a list in a View or in the Group Selector, the selection will jump to that point in the list. This also speeds keyboarding.

Let me begin by saying thank you.

Being a novice to DT-Pro Iā€™ve been struggling with performing this mundane and task. This script has been an incredible timesaver. So far, I really like the product, and am looking forward to learning how to get the most from DT-Pro and D-Agent.

As I am also a complete novice to AppleScript, this was the first script Iā€™ve actually worked with, I was wondering if anyone has any recommendations for a good beginnerā€™s guide?

Cheers,
Jason

Korm - this works a treat - will make creating multiple DBā€™s to focus on data drawn from a ā€˜mainā€™ DB so much easier!

Many thanks! :stuck_out_tongue:

I learned most of what I know by reading other peopleā€™s scripts and sorting out why the script did what it did, and what could be done differently or better. For me, the most extensive location for AppleScript information is MacScripter.net. The AppleScript Language Guide is available among Appleā€™s developer documentation (it is confusingly organized, IMO). Mac OSX Automation is well done and a source of many clever examples.

The script posted above is now available for download through the Support Assistant.

Congrats, korm. Nice to see your contribution available this way.

Exactly what I was looking for. Thank you!

[size=150 KORM: I read your script. Does this still work with latest DTPO and El Capitan?
[/size]

(*
Move the selected record(s) to a destination
that was selectected from the Group Selector panel
20140112.1
*)

try
tell application id ā€œcom.devon-technologies.thinkpro2ā€

  set theDatabase to current database
  set theSelection to selection
  if theSelection is {} then error "Please select something"
  
  set fromPath to (the location of item 1 of theSelection) & (the name of item 1 of theSelection)
  set fromDatabase to the name of theDatabase
  
  set theDestination to (display group selector "Select a Destination")
  if theDestination is {} then error "We had a problem choosing the destination"
  
  set toPath to the location of theDestination
  set toDatabase to the name of the database of theDestination
  
  repeat with thisItem in theSelection
     move record thisItem to theDestination
  end repeat
  
  -- Post the result to the Log
  set movedFrom to "Moved from: " & fromPath & " in " & fromDatabase
  set movedTo to " -- Moved to: " & toPath & " in " & toDatabase
  set theLogEvent to log message (movedFrom & movedTo) info "Mover Script"

end tell

on error error_message number error_number
if the error_number is not -128 then display alert ā€œDEVONthink Proā€ message error_message as warning

end try

Are you having an issue with it?

Not yet! Havenā€™t tried it. Just saw somewhere that all things are working different in El Capitan - donĀ“t want to screw up things so just asking.

Read some different solutions here in the Forum but this one seems to be the latest.

Even better would be to customize the toolbar with a ā€œMOVEā€ symbol but did not find that.

That would be harder to do than you think.

Save the script in ~/Library/Application Support/DEVONthink Pro 2/Scripts/Toolbar and name it ā€œMOVE.scptā€.
Relaunch DEVONthink, right-click the Toolbar and choose Customize Toolbarā€¦You can drag and drop the script to your Toolbar.

Works excellent! Thanks!

Also realized that the function is under Actions in the Toolbar. But easier with a button.

Going through 23.000 mails and sorting them.

Psheww! That sounds like a project! Have fun. :mrgreen:

Hey everyone,

I just discovered this script inside the support assistant and have been strating to use it. However, I just made a mistake and selected the top level database entry which seems to have moved the documents to ā€œno whereā€.

I canā€™t find the documents in the database I selected but they have moved from where they were when I attempted the move.

Two questions:

  1. Are these documents recoverable or hiding somewhere?
  2. Any way this script could be tweaked to avoid this sort of a mistake?

Iā€™m new to Mac OS Automation and wouldnā€™t know where to start with troubleshooting.

Hopefully someone can help :slight_smile:

  1. You need to tell it where the files are supposed to be moved, so where did you choose?

  2. Window > Log should show where the files were moved.

  3. What is the ā€œthe top level database entryā€ ?

@sevalius, I see what you did. In this image I selected the database name instead of a group inside the database. This throws the moved documents into the top level of the database ā€“ the ā€œrootā€. To navigate to the root of a database you choose Go > Top Group.

Itā€™s not a ā€œmistakeā€ ā€“ some users actually like to stuff rarely-used documents into the Top Group.

Here is a version that prevents moves to the root. You need to change property NoTop: to false (no quotes). Compile. Save in a personal folder (one you create) in ~/Library/Application Support/DEVONthink Pro 2/Scripts. The support assistant will not be modified to include this version.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

(* 
Move the selected record(s) to a destination
that was selectected from the Group Selector panel
20140112.1
20170207.3 added optional guard against moving to a database's root
*)

property NoTop : false -- set to true (no quotes) to guard against moving to root

try
	tell application id "com.devon-technologies.thinkpro2"
		
		set theDatabase to current database
		set theSelection to selection
		if theSelection is {} then error "Please select something"
		
		set fromPath to (the location of item 1 of theSelection) & (the name of item 1 of theSelection)
		set fromDatabase to the name of theDatabase
		
		set theDestination to (display group selector "Select a Destination")
		if theDestination is {} then error "We had a problem choosing the destination"
		
		if the location of theDestination is "/" then -- new conditional added in 20170207.3
			if NoTop then error "Cannot move to the database root"
		end if
		
		set toPath to the location of theDestination
		set toDatabase to the name of the database of theDestination
		
		repeat with thisItem in theSelection
			move record thisItem to theDestination
		end repeat
		
		-- Post the result to the Log
		set movedFrom to "Moved from: " & fromPath & " in " & fromDatabase
		set movedTo to " -- Moved to: " & toPath & " in " & toDatabase
		set theLogEvent to log message (movedFrom & movedTo) info "Mover Script"
		
	end tell
	
on error error_message number error_number
	if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	
end try

Thanks @korm.

Appreciate the changed script.

-sevalius

I know this is an old post, but Iā€™m wondering: Can this script can be configured as a trigger script that can be attached to a group?

Thanks!