Create Hook URLs for a specific PDF page in DEVONthink

DEVONthink can create URLs for a specific PDF page which look like the following:

x-devonthink-item://7C28D0EE-7E51-4652-9690-6466694CE294?page=0

I customized the default Hook AppleScript in order to get links like the above as following:

tell application id "DNtp"
	if exists (content record of window 1) then
		-- current open item
		if type of (content record of window 1) is PDF document then
			set RecordLink to the reference URL of (content record of window 1)
			set PDFpage to current page of window 1
			set DEVONthinkLink to RecordLink & "?page=" & PDFpage
			return DEVONthinkLink
			
		else
			return reference URL of (content record of window 1)
		end if
	end if
	
	if class of window 1 is in {viewer window, search window} then
		set selected_items to selection of window 1
		if (count of selected_items) = 1 then
			if type of item 1 in selected_items is PDF document then
				
				-- current selected item
				set RecordLink to the reference URL of item 1 in selected_items
				set PDFpage to current page of viewer window 1
				set DEVONthinkLink to RecordLink & "?page=" & PDFpage
				return DEVONthinkLink
			else
				return reference URL of item 1 in selected_items
			end if
			
		end if
	end if
	
	-- selected group
	return reference URL of root of window 1
end tell

If I execute the script from the Script Editor it works fine. But when I activate the Copy Link command from Hook I get a URL without the “?page=0” part.

Any help is welcome!

Try adding an activate

This would be a very useful script if it works out.

I was trying the script with DEVONthink 2. After installing DEVONthink 3 it works!

1 Like

Thanks – I can see using this on a page of a lengthy PDF to use Hook to link an extensive note to that page. Cool idea, I urge CogSci to incorporate your idea into the baseline set of scripts (@LucB)

1 Like