Searching for terms in Skim.app using Applescript

68 Views Asked by At

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?

1

There are 1 best solutions below

0
Robert Kniazidis On

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