I have a program that works with the selected text of a pdf within DT3 and I want the program to also highlight the selected text in the pdf. I haven’t found a good way to do this, so I am trying to use a mac keyboard shortcut attached to the DT3 ‘highlight yellow’ command from within the script using system events and keystroke. I have a program below that works when I run it from scriptdebugger (i.e., the pdf selection is highlighted), but won’t work when I attach the script to its own keyboard shortcut and run it in DT3. I think it has something to do with which application is active when, but I don’t know enough to figure out the issue.
Oddly, if I close and reopen DT3, I can successfully invoke the script using the keyboard shortcut exactly once (i.e., the pdf selection is successfully highlighted), but it won’t work if I invoke it again.
Here is the script that tries to call my shortcut for Highlight Yellow, which is shift-ctrl-y (note that it doesn’t work if I remove the line to activate the application DEVONthink 3):
on run {}
tell application id "DNtp"
try
tell application "DEVONthink 3" to activate
tell application "System Events" to keystroke "y" using {shift down, control down}
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
end try
end tell
end run
Any advice? If there is an easier way to highlight a selection of pdf text from within applescript, I am open to that also. Thanks in advance.