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"
try
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!