Dear @cgrunenberg and @LucB,
There is one issue with this script. Hook can’t get the link from a folder in DT (for PDF file and video file, it works well). Any idea for this issue?
I’m not seeing any issue with getting the reference URL from a group in DEVONthink. However, I also just rewrote the Get Name and Get Address scripts…
Get Address
tell application id "DNtp"
if exists content record then
-- A content record is also a property of the application
-- Content record applies to all think windows
-- If a document window is open, there IS a content record
-- A viewer window requires the view/edit pane to be visible to have a content record
return reference URL of content record
end if
if class of think window 1 is equal to viewer window then
if selection of think window 1 ≠ {} then
set sel to (selected record 1) -- Get only the first selected record
return reference URL of sel
else
-- The group selected in the Navigate sidebar is the root of the window
return reference URL of root of think window 1
end if
end if
end tell
Get Name
tell application id "DNtp"
if exists content record then
-- A content record is also a property of the application
-- Content record applies to all think windows
-- If a document window is open, there IS a content record
-- A viewer window requires the view/edit pane to be visible to have a content record
return name of content record
end if
if class of think window 1 is equal to viewer window then
if selection of think window 1 ≠ {} then
set sel to (selected record 1) -- Get only the first selected record
return name of sel
else
-- The group selected in the Navigate sidebar is the root of the window
return name of root of think window 1
end if
end if
end tell
Does that work for you?
Dear @BLUEFROG,
Thanks but it is actually not what I wanted. Your new scripts are somehow similar with the default scripts in Hook which means I can retrieve the group or file markdown link (clickable URL) but without deeper parameters in it.
However, what I wanted, also the topic of this discussion here, is that I can retrieve the page link from the PDF file or the frame link from the video file. In addition, the name can be changed accordingly by adding the page number or frame offset time such as [DT Help page 3](x-devonthink-item://<uuid>page=3)
, something like this.
For group, since there is no parameter of page or frame, just remain like [DT folder](x-devonthink-item://<uuid>)
.
You can refer to the scripts that @cgrunenberg wrote below.
As to blocks: there are some objc frameworks where they’re needed as kind of callback functions. And I was not able to figure out how to do that in JXA. Anonymous functions don’t work.
The rest (Scriptable, nose) is too off-topic here.
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
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
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.
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.
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.