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
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?
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.
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?
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.
[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
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.
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:
Are these documents recoverable or hiding somewhere?
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.
@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