Thanks, @Grantst . We’ve indeed received requests for deep linking to DEVONthink PDFs, given that Hook supports deep links to several PDF apps. I see two cases, the second of which has two cases.
if a user wants a deep link to a file that is merely indexed by DEVONthink but not in DEVONthink’s database, and if the user is content to get a hook://file/ URL, then we may be able to devise a deep link for the file. That file however would (at least for time being) open in the app implied by the macOS > Finder Open In setting for that file.
if the user wants a deep link to a PDF in a DEVONthink database per se, then DEVONtechnologies would need to specify the x-devonthink-item URL format , because DEVONtechnologies owns that protocol scheme. For PDF files in Finder, we at CogSci Apps Corp. settled on a syntax an instance of which looks like this #p=2&x=0&y=0 (page number, and x/y per PDF spec (we have variants of that. ) The x and y in our case are optional; p gets the user to the right page. If DEVONtechnologies were to provide such a URL scheme, then they might want to go the extra mile and provide a getDeepURL method, otherwise Hook (and other automation) could construct the URL from AppleScript. The key is that the resultant deep URL gets honored. Otherwise, the URLs would only work inside Hook, and Hook would need to be the “middle person”, which we try to avoid doing; it’s good for users to be able to paste links anywhere and use them only with the target app. I.e., if there’s no x-devonthink-item deep URL, to make deep links to the DB would require a special hook://devonthink scheme --not ideal.
Many Hook users are DEVONtechnologies users. We at CogSci Apps Corp. value integration with DEVONthink. We would be happy to add deep linking here.
The x-devonthink-item URLs in Hook would be synced to our upcoming iOS/iPad software, which also syncs x-devonthink-item URLs in the current format.
Welcome, @LucB! In case of DEVONthink the x-devonthink-item://<uuid> scheme supports already additional parameters like page (zero-based page number) or time (offset in seconds in audio/video file). Such item links can be copied in the user interface via the contextual menu. Or created via AppleScript like this:
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)
else if (count of selected records) is 1 then
return reference URL of selected record 0
This is stunning! Thank you, both of you (and the companies you represent), for working together in this fashion to bring more excellence to us users. Contrasting this with DEVONtech’s attempts to raise issues with some other vendors via obscure and frustrating support channels just makes it all the more pleasing to see how things work when two great companies meet.
wow this is great! i used to open the videos from the database externally in QuickTime to get frame link using hook. just now I replaced the script in hook with the one you posted here, it works really great. this saves a lot of time and makes things easier. thanks a lot
edit: for some reason, the links only works in my note taking app if I copy paste through hook. directly copying from DT doesn’t work as a link. [pic] the first pasted using hook. the second directly from DT
Sorry to dredge this thread up from February, but I’m hoping you’re still keeping track of notifications here : )
I work entirely within DevonThink for my research, including using DevonThink’s PDF reader to access my (1000s of) research PDFs from various organizing folders. When I use a devonthink link to a research PDF, it just goes to page 1. Being able to “deep link” directly to the page of a very large PDF would be a game changer.
SO. Here’s my question: this post seems to be contemplating new additions to Hook (rather than existing functionality). But is that wrong? Is there some way for me to “deep link” directly to (let’s say) page 256 of an 800 page PDF using Hook if I’m working in Devonthink?
This works quite well to get the address of page or frame with Hook and saves me lots of time!
But I also want to know how I can change the name of the link by adding page number or frame time. For example, I have PDF file named DT Help. When I use your scripts, no matter which page or frame, the return markdown link is [DT Help](x-devonthink-item://<uuid>page=3). I want to modify it as [DT Help Page 3](x-devonthink-item://<uuid>page=3) automatically.
I tried by myself some coding of AppleScript in Hook’s Get Name interface. But I am quite not familiar of the syntax, I failed to solve it. So could you help me?
The default codes of getting name in Hook is as following
tell application id "DNtp"
if exists (content record of current tab of window 1) then
-- current open item
return name of (content record of current tab of window 1)
if class of window 1 is equal to viewer window then
set selected_items to selection of window 1
if (count of selected_items) = 1 then
-- current selected item
return name of item 1 in selected_items
-- selected group
return name of root of window 1
Apparently, @cgrunenberg’s code posted above creates the correct DT link (i.e. one to a certain page). Now, the code you posted only shows us how to get the name of a DT record. What we’d need to see is the actual code that Hook (I assume what you posted is somehow used in Hook) uses to assemble its link. Since the DT link already includes the page number, it should be trivial to append it to the name of the link (or rather the link text, since a name is actually an attribute of a link that’s not coming into play here).
So somewhere someone does something like set the link to "[" & DTname & "](" & DTURL & ")"
(not verbatim, though!) and that’s the place where you’d want to change the code: Extract the page no from DTURL and append it in the form "Page " & pagenumber as string to the part in brackets above.
@chrillek Thanks for your reply and sorry for missing info.
From my understanding by looking at the Hook user interface, in Hook, Get Name and Get Address are separated (as shown in the below figure). I actually pasted @cgrunenberg scripts to Get Address part and in the Get Name part I need to modify the scripts accordingly to change the name of the Markdown link as I wrote and requested in my last thread.
So my request is how to modify here. Any advice is very appreciated since I am struggling to deal with the AppleScript syntax.
Thanks for the explanation, that makes it clearer now. Basically you have to copy/paste the part of the Get Link script that gets the page no, ie set thePage to current page of theWindow
into the Get Name script and return a value for the name as you see fit. Something like &” page “& thePage at the end of the current definition of the name.
Unfortunately, the variables are named differently in both scripts, so you’d have to figure out what theWindow refers to.
I’m sure is not too complicated, but I’m not going down the AppleScript road.
Rosemary Orchard says in this podcast that she has found situations where the same script command works with Applescript but will not work with JXA due to bugs in the way JXA is implemented by Apple. Thus she prefers Applescript over JXA.
Have you (or others) experienced similar situations? Any specific examples of known situations where Applescript works but the JXA version does not?
Then, if we’re talking ObjC, there’s the question of blocks: AS has them, some ObJC methods require them, but I have no idea how to provide them with JXA.
It might actually be worth exploring other JS approaches like node. In any case, when I said “I’m not going down the AppleScript road”, I was more talking about the language as such. The more I look at it, the more painful it gets. And it does not even have a defined grammar (afaik), so is it even a programming language in the proper sense of the term?
PS: The link you posted leads to a website requiring registration. Another road I’m not going down (anymore).