Deep Linking Hook

That’s indeed true Jim. So far most JXA issues I’ve encountered come down to bugs, rather than inherent problems with JXA.

That’s quite different to my experience - so far most “fixes” for JXA were just workarounds as it was actually a shortcoming/bug of JXA. E.g. like this one:

DEVONthink will handle this but shouldn’t have to.

I see - we’re talking about the same thing here, from my perspective it seems like a bug, but as a developer from your perspective I now understand they are JXA bugs. Too bad the JXA implementation seems so brittle :frowning:

You mean that DT is actually fixing a JXA shortcoming by use of a workaround?

Exactly.

I did read the manual and support documents but I cannot find a way to link specific Markdown sections or rich text paragraphs. Is there an explanation or link you can point me to so I can create a “deep” link to a specific section of a document? Thank you!

That’s e.g. possible via the contextual menu in the text editor or via the Table of Contents inspector too.

Thank you!

Dear Sheng, I found [johnsidi]'s ( @ hook forum) script worked well for me to get URLs for a specific PDF page using hook. Maybe it will work for you.

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

Thanks @oriexm
Scripts @cgrunenberg provided above could already get the PDF page through Hook.

The new browser Arc has a “copy to highlight” feature which works pretty good. Is this maybe a good option for DT, too?

In Arc it generates your post as:

(main address)/t/deep-linking-hook/69403/10#:~:text=You%20can%20actually%20create%20links%20in%20DEVONthink%20to%20e.g.%20PDF%20pages%2C%20Markdown%20sections%2C%20rich%20text%20paragraphs%20or%20to%20a%20video%20frame."

It seems like a search query so it should work only for longer highlights and not for example one word. But its good enough I think.

Item links support already ?search=text queries, a script could be used to generate them for the currently selected text.

1 Like

That’s nice. The only problem is that I don’t have any scripting skills. Sadly, I’m one of those who can only rely on other knowledgeable people.

Does somebody know how to do this? That would be really nice.

@LucB ?

As a newbie to Hookmark and DTP, could someone direct me how to use this AppleScript?

Does it go into the App section in Hookmark or is it a Script I run from the DTP AppleScript menu?

How does this integrate with with hook
Thanks

There’s a section on “Automation” in DT’s manual (which you find under the Help menu). It describes the usage of scripts as well.

1 Like

Is Hook still necessary after the last update, because deep linking is now possible in DT3?

Hook is used for more than DEVONthink, so I guess that depends on your use of it.

Resurrecting this very interesting thread as it seems from a Hook YouTube video, it should now be possible to link directly to a page in a PDF opened in DT3 native pdf app.

However… when I try that, the hookmark link is: worldview management for better business_v1.2-edited & upgraded.pdf

and clicking on that link only takes me to the PDF in DT3, it does not open the PDF in DT3 to the correct page.

I tried to link to the page using Highlights App, and when I click on that link it opens the document in the Mac default app ‘Preview’ on the first page.

any suggestions?

You might want to take a look at this thread @joe.lafferty

thanks @AW2307
I’ll check this out.
however while this looks super helpful to automate the page number and make it visible, I’m not sure it will address my problem as the hook link does not seem to be ‘deep linking’ at all. just taking me to the file in DT3, not opening the file in DT’s pdf app, never mind opening it to the correct page!
there seems to be something more fundamentally wrong…

Did you modify the integration script in the Hookmark settings? The option to modify scripts is only available in Hookmark Pro as far as I know.

The default script doesn’t link to a specific page, so you need to add the one from this post:

tell application id "DNtp"
	set theWindow to think window 1
	if exists content record of theWindow then
		set theURL to reference URL of content record of theWindow
		set thePage to current page of theWindow
		set theTime to current time of theWindow
		if thePage is not -1 then
			set theURL to theURL & "?page=" & (thePage as string)
		else if theTime is greater than 0.0 then
			set theURL to theURL & "?time=" & (theTime as string)
		end if
		return theURL
	else if (count of selected records) is 1 then
		return reference URL of selected record 0
	end if
end tell