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)

2 Likes

Having specific hooks to specific pages of a long PDF would be particularly great in the enterprise and for attorneys and litigators. Courts gets hyperlinked courtesy copies of briefs and documents. That way the court can click on a cite and go directly to a page of an exhibits. When you put one Hook to a pdf it goes to the page where you put the hook. But if you put another hook on the same PDF both Hooks go to the last hook page for the you made. If Hook can fix it so you can put many hooks to the same PDF it would be a game changer.

1 Like

you’ll very soon be able to Copy Link to get to the specific page. That hook would need to be pasted in an associated documented however, as Hook only presents one link per target resource in the Hook window (with the exception being Pinned – i.e., a pinned bookmark can repeat something that is also contextually hooked).

1 Like

So is this possible right now? The Script above does not quite work for me, where would I add an activate? Thanks!

Yes it is available. Please make sure you delete any overrides of the built-in PDFPenPro script in Scripts Tab – Hook.

Just select the PDFpenPro script there, and click on the - button. That way you will get the default integration. Please use Hook 2.2.2.

Hi, PDFPenPro? I’m looking for DevonThink Pro Page Links :wink:

ooops… same principle /page applies .

There is Using Hook with DEVONthink by DEVONtechnologies – Hook. And here is a page where we describe an alternative DEVONthink integration: Customizing Hook Integration with DEVONthink – Hook. Each page has an HTML link to the other.

But neither the default integration nor the Custom Integrations are able to link to specific pages of PDFs in DevonThink like ohnsidi proposed?

Sorry!!! I seem to have mixed topics (hence my mentioning PDFpenPro) [i switched too fast between customer support; other Hook tasks; and academic work.] Hook currently only supports deep links to PDFpenPro and Skim. PDFoo supports deep linking, but you’d need to use its Copy Link function. Not as robust or convenient as Hook’s deep links. If they add an API for deep linking we would likely support it. Deep-linking aside, PDFoo works fine with Hook. There’s also an alternative Hook script for Curio. In Hook 2.3, Adobe Reader DC and Adobe Acrobat will get deep PDF linking too.

Now that we have the infrastructure in place, we’ll look at deep PDF linking for DEVONthink.

Please keep in mind that Hook’s deep PDF linking main use cases revolve around Copy Link and Copy Markdown Link , rather than hooking (bidirectionally linking). Hook will currently only show you one HOOKED entry per destination document. However, for each deep Copy Link or Copy Markdown Link, Hook will add a bookmark. You can find each bookmark with Hook’s search tool. Hook’s bookmarks may be renamed, for ease of processing.

We’re quite committed to deep PDF linking to support researchers, lawyers and all other deep PDF users. We also value DEVONthink integration.

2 Likes

Thanks, and thanks for the explanation! Just one thing: What is PDFoo ?

1 Like

It’s a PDF reader available on App Store: ‎PDFoo on the Mac App Store. The link to their website is broken.

It’s not that we’re recommending or endorsing the app, however. We simply provided integration based on user requests.

Any chance that this is in the future near horizon?

Yes, this is on our list. We’re interleaving integrations with new software (3.4.2, 3.5 public beta, and an update to our iOS beta are all nearly ready).

DEVONtechnologies kindly provided some info we can use: Deep Linking Hook - DEVONthink - DEVONtechnologies Community

2 Likes