I’d like to create a macro that would allow me to search for a selected string (a string that I select manually in my translation editor CafeTran) in an open PDF file. This file would be displayed on a second screen, though I don’t think that’s relevant here ;). Just want to mention all parameters.
It’s not crucial which viewer is used for the search (Preview, Acrobat Reader …).
The macro should allow Find again, if the first instance of the search string isn’t the one that you were looking for. It would be ideal if the found string would be highlighted in the PDF.
I would prefer a solution via scripting or so, not with send keys, so that my CafeTran doesn’t lose focus.
Did someone create a solution for this in the past or can give me a hint to set up the search?
This doesn’t work:
activate application "Adobe Reader"
tell application "System Events"
tell process "Adobe Reader"
click menu item "Find" of menu 1 of menu bar item "Edit" of menu bar 1
keystroke "v" using {command down}
end tell
end tell
The clipboard content is sent to the applescript editor
Now I’m still looking for a comparable solution to search PDF files. Looks like Skim can be used for this:
find v : Find text in a document.
find document : The document in which to search.
text text : The text to search for.
[from list of specifier or specifier] : The selection to search from.
[backward search boolean] : Search backward?
[case sensitive search boolean] : Is the search case sensitive?
→ list of specifier : Selection for the found text as a list of character ranges.
Anyone, who’s familiar with scripting Skim from Keyboard Maestro? Especially with the Find text command?
set textToFind to get the clipboard
tell application "Skim"
set foundText to find front document text textToFind
select foundText with animation
end tell
I have not been able to find any examples of using:
from list of specifier or specifier] : The selection to search from
So I'm unsure if there's a directly scriptable method of finding the next instance. Maybe, maybe not.
From there you can set the find-pasteboard in Keyboard Maestro to the clipboard and find-next in Skim using either Keyboard Maestro or an AppleScript.
tell application "System Events"
tell application process "Skim"
set frontmost to true
tell menu bar 1
tell menu 1 of menu bar item "Edit"
tell menu 1 of menu item "Find"
click menu item "Find Next"
end tell
end tell
end tell
end tell
end tell
It does not appear that Skim supports UI-Scripting in the background, so either way you're going to have to activate Skim, find-text, and then return to the app you're working in.