Note: This initial script was only the starting point and should not be used. Please scroll down to find Christian’s script.
I am maintaining a few databases, and all of them contain at least several indexed groups (folders). The folders that these indexed groups point to get frequently modified outside of DT. Whenever one visits on of these groups, indexed items are updated on the fly. However, there are two situations where this is not good enough: (1) Search and (2) Synching to DevonThinkToGo. So far, I have kept my indexed groups updated periodically by manually going through all databases, and using the “File > Update Indexed Items” command. Even with my 5 databases, this gets tiring. Below is a script that globally udpates all indexed groups across all my databases. I used GUI scripting to accomplish this. To call up all the databases, I use the workspaces (see Go menu). I save top-level views of all my databases as workspaces. The script can then call them one by one, using the key shortcuts (CMD-OPT-n, where n is an integer).
-- 24-Mar-2014, GG
-- This script goes through all my databases and updates their index folders; this is useful to update all indexed files prior to a sync to DevonThinkToGo on the iPad, e.g. when getting ready for a trip. Without this script I have to sync each database by hand, by going to the top level, selecting all group, and using "File > Update Indexed Items".
-- Implementation: Each database is saved as a "Workspace", such that the top level group is displayed (see Menu "Go - Workspaces"). Once they are created, they can be accessed by the shortcuts "CMD-OPT-n", where "n" is an integer. We then loop through these workspaces using GUI scripting, select all groups at the top level, execute the "Update Indexed Items" command, and then deselect, and move to the next database (i.e. workspace).
tell application id "DNtp" to activate
-- set the workspace numbers for all the databases to be updated
set work_space_list to {"1", "2", "3", "4", "5"}
tell application "System Events"
tell process "DEVONthink Pro Office"
repeat with work_space_item in work_space_list
-- GUI scripting of the key combo to call up a workspace
keystroke work_space_item using {option down, command down}
tell menu bar 1
tell menu bar item "Edit"
tell menu "Edit"
click menu item "Select All"
end tell
end tell
tell menu bar item "File"
tell menu "File"
click menu item "Update Indexed Items"
end tell
end tell
tell menu bar item "Edit"
tell menu "Edit"
click menu item "Deselect All"
end tell
end tell
end tell
delay 1 -- add a delay if desired to follow by eye what's happening
end repeat
-- at the end of the sequence, move back to displaying the inbox (workspace 6)
keystroke "6" using {option down, command down}
end tell
end tell
One thing I haven’t figured out yet: When I run this script from the Applescript Editor, it nicely executes and I can visually follow all the database switching, selecting etc. When I copy the script into the DT script directory, it executes, but I don’t see the visual progression; but at the end, the updating seems to have worked.
Correction: Calling the script through the script menu does not seem to work reliably. Any suggestions?