Script to search the selected text from Safari in DT Pro

I’m trying to write a script that will send a search query to DT Pro’s search field in the main window, not the search window. The search query is some selected text in Safari. I started modifying a script that came with DT Pro created by Christian Grunenberg. I’m having problems with the search command. I tried many different ways and used pieces of code I found in the forum, but nothing worked.

I have a temporary solution that I created with QuickKeys, which is something like a visual programming tool to create GUI scripts. The problem is it switches the focus from Safari to DT Pro when I run the QuickKey shortcut. I’m hoping that by using the DT search command inside a new script it will perform the search in the background without switching from Safari to DT Pro. The reason I don’t want it to switch is because I’m using another app called MondoMouse to create a “seamless” interaction between Safari and DT Pro. MondoMouse automatically focuses the window that is below the cursor. So every time I run the QuickKey shortcut it tries to switch the focus to DT, but my mouse cursor is above Safari so MondoMouse tries to grab the focus back. It works fine when I don’t move the mouse, but most of the time I don’t hold still on time and a brief jittering switch dance starts.

Here is the script:

tell application "Safari"
		if not (exists document 1) then error "No document is open."
		set this_selection to do JavaScript "unescape(getSelection())" in document 1
		tell application id "com.devon-technologies.thinkpro2"
			search this_selection
		end tell
	on error error_message number error_number
		if error_number is not -128 then display alert "Safari" message error_message as warning
	end try
end tell

Any help would be appreciated!

The “search” command doesn’t use the interface, it’s returning the found results so that they can be evaluated by a script.

There are no commands to use the search window or the toolbar search. But you might have a look at the “Lookup” service provided by DEVONthink although this is also activating DEVONthink.

Besides also activating DT, the Lookup service uses the search window. I want to use the toolbar search because I have my windows set up so that DT is like a sidebar next to Safari. And with MondoMouse, it’s just like my previous setup in Firefox with the bookmark sidebar open. Also, I like how the toolbar search starts showing results right away without pressing enter. Little things like that speed up my workflow and I keep discovering new ways thanks to DT’s scripting support.

Thanks anyway! :slight_smile: