Calling this handler after you’ve set a viewer window's query via AppleScript adds it to DEVONthink’s history.
Calling the handler:
my writeQueryIntoDEVONthinkHistory()
Handler:
on writeQueryIntoDEVONthinkHistory()
try
activate application id "DNtp"
tell application "System Events"
tell process "DEVONthink 3"
set theTextFields to text fields of groups of toolbar 1 of window 1
repeat with theseTextFields in theTextFields
set theseTextFields to contents of theseTextFields
if theseTextFields ≠ {} then
set thisTextField to item 1 of theseTextFields
set focused of thisTextField to true
key code 36
end if
end repeat
end tell
end tell
on error error_message number error_number
activate
if the error_number is not -128 then display alert "Error: Handler \"writeQueryIntoDEVONthinkHistory\"" message error_message as warning
error number -128
end try
end writeQueryIntoDEVONthinkHistory
Hi @pete31 - Thanks for sharing your script! By chance, do you know where the search history is actually stored in DEVONthink (i.e., whatever is filling the “Recent Searches” field)?
The reason I ask is that I’d like to create an Alfred workflow that gets my search history and allows me to quickly filter through it and rerun past searches (e.g., similar to those for Safari, Chrome, etc.). While the latter part is easy enough to build, I have no idea where to get the search history from.
It’s got to be sitting in a plist file or something similar, right?
You can get it via vanilla AppleScript or AppleScriptObjC.
AppleScript version
AppleScript version
-- Get ToolbarSearchRecents from plist (AppleScript version)
tell application "System Events"
tell property list file "~/Library/Preferences/com.devon-technologies.think3.plist"
set theToolbarSearchRecents to value of property list item "ToolbarSearchRecents"
end tell
end tell
However, you probably notice that it’s a bit slow.
AppleScriptObjC version
A script library with AppleScriptObjC requires a little setup but it’s a lot faster.
AppleScriptObjC version
-- Get ToolbarSearchRecents from plist (AppleScriptObjC version)
-- Save this script in ~/Library/Script Libraries
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
on getToolbarSearchRecents()
try
if current application's id = "com.devon-technologies.think3" then
set theDefaults to current application's NSUserDefaults's standardUserDefaults()
else
set theDefaults to current application's NSUserDefaults's alloc()'s initWithSuiteName:"com.devon-technologies.think3"
end if
set theToolbarSearchRecents to ((theDefaults's dictionaryRepresentation())'s objectForKey:"ToolbarSearchRecents") as list
on error error_message number error_number
activate
if the error_number is not -128 then display alert "Error: Handler \"getToolbarSearchRecents\"" message error_message as warning
error number -128
end try
end getToolbarSearchRecents
To create a script library:
In Finder:
press ⇧⌘G
paste ~/Library/Script Libraries
if no window is opened
paste ~/Library/
create folder Script Libraries
In Script Editor.app
create new document
paste this script
press ⌘S
press ⇧⌘G
paste ~/Script Libraries/
save
To call the script library in your script (replace script "Get ToolbarSearchRecents from plist" with your script library’s name):
set theToolbarSearchRecents to script "Get ToolbarSearchRecents from plist"'s getToolbarSearchRecents()