0

Im trying to open the app Skim from Alfred and search for a particular phrase:

    on run argv
  set theQuery to item 1 of argv
  tell application "Skim"
    activate
    open "/Users/username/Dropbox/xys.pdf"
    set foundText to find front document text theQuery
    select foundText with animation
  end tell
end run

This kind of works, it 'finds' one instance of the word and highlights it.

However I would like it to 'search' for all instances of the word and show the results in the left hand side pane.

Any ideas how to modify my applescript to achieve this?

  • I don't think that skim offers access to the sidebar find. You might be better off trying to get your script to trigger the Edit > Find > Search PDF command (e.g. type command-option-f). – Mockman May 03 '23 at 15:14
  • It is possible to select and highlight without GUI scripting all occurrences of the searched text in PDF (I can show how), but the panel on the left does not react to this. – Robert Kniazidis May 03 '23 at 17:06
  • @RobertKniazidis I would appreciate it if you could show me that! – Deon O'Brien May 04 '23 at 09:05

1 Answers1

0

The comments above have already said that without the use of GUI scripting, displaying the found cases of the word/text in the panel on the left is impossible.

It is possible, however, without GUI scripting, to find and select (highlight) the word/text in all pages of the document. At the request of the user @Deon O'Brien, I am publishing this solution.

set theText to "BOOL"

tell application "Skim"
    activate
    -- open "/Users/username/Dropbox/xys.pdf" -- optional, if the document is already opened
    tell document 1
        set theResult to {}
        set foundText to find text theText
        repeat until foundText is {}
            set end of theResult to foundText
            set foundText to find text theText from foundText
        end repeat
        select theResult with animating -- animating optional
    end tell
end tell
Robert Kniazidis
  • 1,760
  • 1
  • 7
  • 8