Script: Add query that was initiated via AppleScript to DEVONthink history

Hey there, I seldom use DEVONthink’s search via the toolbar as I use an Alfred workflow that opens search results in a new window.

However sometimes I’d like to redo a search via “Recent searches” in the toolbar drop down …

Recent Searches

… but currently that’s not possible because “Recent searches” doesn’t list searches that were initiated via AppleScript.

So what do you think? Would the possibility to redo AppleScript searches via “Recent searches” be handy?

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

1 Like