Put a ?search= link on the clipboard

Probably mentioned in the forum before, but worth calling out, given the recent dialogs on annotations.

Say, you have a PDF with this text highlighted:

And you want a link to put in an annotation - or wherever - that will find that text in that document.

You want a link like this:

[size=85](PHPBB truncates long strings, so the display is not accurate)[/size]

This little script puts that link on the clipboard. There’s a setting to throttle the maximum length of the search string, but that’s mainly for convenience.

-- use: with a PDF open in a DEVONthink window, select some text
-- that you want to link to
-- run this script
-- the link to that text in that document is on your clipboard
-- This script might be assigned to a keyboard shortcut - QuickKeys, etc.

set MaxLen to 1000

tell application id "com.devon-technologies.thinkpro2"
	set theSelection to selection
	if theSelection is {} then error "Select an item, please"
	repeat with thisItem in theSelection
		set theCitation to selected text of think window 1
		if theCitation is "" then error "Select some text, please"
		if length of theCitation is greater than MaxLen then error "That selection is longer than " & MaxLen
		set theCitationEncoded to (do shell script "php -r 'echo trim(urlencode(" & "\"" & theCitation & "" & "\"));'" as string)
		set the clipboard to the reference URL of thisItem & "?search=" & theCitationEncoded
	end repeat
end tell

All instances of the search text are highlighted, and you may navigate the instances using ctrl-command-[right or left arrow]