-- Search in Skim for the text from the clipboard,
-- progressively shortening it from the end until found
-- or until only 3 letters remain.
-- onmiddellijk, regel
property minLength : 3
on searchClipboard()
set theWord to get the clipboard
set wordLength to (length of theWord)
tell application "Skim"
activate
set docRef to front document
repeat while wordLength ≥ minLength
set textToFind to text 1 thru wordLength of theWord
set foundText to find docRef text textToFind
if foundText is not {} then
select foundText with animation
exit repeat
else
set wordLength to wordLength - 1
end if
end repeat
end tell
end searchClipboard
-- Run it:
searchClipboard()
I recommend get whole text from PDF and replace hyphen. Then you can search whole text and get hit lines.
So, I show the de-hyphenate script.
It may work as you think. But it may help you, I think.
Getting body text from PDF is very very easy task for Skim+AppleScript or PDFKit+AppleScript.
Incremental search may not fit with AppleScript way.
So, you have to think of it as you want.
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
-- Target text (for test)
set inputText to "This is an inter-
national agreement.
The co-oper-
ation continues.
But the number -100 should stay.
-- comment line"
set nsText to current application's NSString's stringWithString:inputText
set regexPattern to "([A-Za-z])-(?:\\s*\\r?\\n\\s*)([A-Za-z])"
set theRegex to current application's NSRegularExpression's regularExpressionWithPattern:regexPattern options:0 |error|:(missing value)
set newText to (theRegex's stringByReplacingMatchesInString:nsText options:0 range:{0, nsText's |length|()} withTemplate:"$1$2")
set outputText to newText as text
return outputText