Using Hook to generate DEVONthink links within other applications?

I use DEVONthink to store all my work-related files (I’m a freelance writer and researcher). It offers a ton of features that help me manage the many different projects I’m working on. In my markdown notes, I heavily rely on creating links between documents to help me organize and quickly access relevant information.

File transclusion and [Wiki Links] aren’t standard features in markdown or MultiMarkdown, so most applications have different ways of handling it. I’ve been using DEVONthink and Notebooks together, with the latter as a makeshift front end for the former. (I don’t like using DEVONthink’s text editor, so I use Notebooks instead.) DEVONthink indexes my Notebooks files into a separate read-only database. I make all my edits in Notebooks, but I render the files in DEVONthink. Since both applications use MultiMarkdown, the two apps work well together. (Obsidian and many similar “second brain” applications use different flavors of markdown that are less compatible with DEVONthink.)

There are a few different syntaxes I could use for linking documents. My preferred route is to use x-devonthink-item links. (In my setup, this syntax is more straightforward than using /links/to/the/full/filepath.md or application-specific URLs ie. notebooks://show/My%20Life/Reading%20Notes/TEMPLATE.md.)

I think Hook might be able to help me automate my inter-document linking process and alleviate some cognitive burden. Hook’s “Copy Markdown Link” command has been a major time-saver for me. But still, it requires a bit of an awkward workflow in my case where I need to switch back and forth between different application windows a few too many times.

When I invoke Hook’s “Copy Markdown Link” command within Notebooks right out the box, Hook will create a Notebooks-style markdown link ie. [document name](notebooks://show/path%20to%20file/document%20name.md). I would prefer if Hook could generate a DEVONthink-style link ie. [document name](x-devonthink-item://2B465F34-7748-4340-B177-137B3F1AC301). Before I invest too much time mucking around in the code (I’m not much of a programmer), I’m looking for some guidance. Would it be possible to change the Hook script for Notebooks to force it to generate DEVONthink-style markdown links rather than Notebooks-style markdown links? I figure I might be headed in the right direction since I’m opening the same markdown note file in both applications.

It’s possible to modify Hook’s integration with just about any app. So Notebooks would qualify. Notebooks doesn’t have an API for linking, unfortunately. So Hook uses UI Scripting to integrate with it. All any software can get from Notebooks is its notebooks:// URL. So one would need to ask the developer to provide an API to get the path. That would be less than a day’s work for a competent Mac developer there to do.

Once you get a handle on the file:// path, the question is whether this can be fed to x-devonthink-item URL to get the x-devonthink-item URL. That’s a question for the DEVONthink forum. If that is possible, then yes it would be possible to modify Hook’s integration script. It would communicate with Notebooks first, and then open DEVONthink and make a request to DEVONthink to get the URL.

I imagine the above would work. The DEVONthink team and forum are quite responsive. Also Eric Böhnisch-Volkmann, President of DEVONthink , is a co-signatory of the Manifesto for Ubiquitous Linking. So he definitely values linking and DEVONthink has long supported linking. Hopefully the Notebooks dev will understand the importance of this.

Thanks for the feedback!

It seems to me that notebooks:// URLs are generated in a relatively predictable way, in which case it shouldn’t be too hard derive the file path from them. I haven’t confirmed this 100% yet, but as far as I can tell, notebooks:// URLs mirror the file path starting at the Notebooks Home directory (which is by default set to iCloud at ~/Library/Mobile Documents/iCloud~com~aschmid~notebooks/Documents and can be changed in the app’s preferences), albeit spaces are replaced with %20. I think I’d be able to come up with a RegEx script that could convert from notebooks:// URLs to file path. @LucB, does that seem like I’m on the right track or am I missing something?

1 Like

interesting. the next thing to check would be whether they change if you rename or move the file within Notebooks. Suppose the file is first called “foo” and the link reflects “foo”, then the note is renamed to “bar”. Does the notebooks URL then change? If not then if/when you feed the link with name “foo” into DEVONthink presumably DEVONthink will not be able to find the path…

1 Like

I’ve only been experimenting with these details in my workflow for a few days, so IDK if there might be exceptions to the rule I’m about to describe.

I’ve noticed that if the first line of my document in Notebooks says Title: Example Title, the filename will usually change to Example Title.md (sometimes I have to right-click the file in Notebooks and choose Rename for this change to take effect). But most importantly, the filename will remain constant from that point on, as long as I don’t manually rename it. It seems the Title metadata key stop the filename from automatically changing. And the notebooks:// URL seems to stay fixed, too. If I move the document to another folder in Notebooks, the URL automatically adjusts to follow the same pattern I described in the previous post such that it reflects the file path.

I would need to dive into the DEVONthink AppleScript dictionary to figure out the specific functions to call, but I am almost certain that there’s an easy way to derive the x-devonthink-item:// URL from a file path.

1 Like

This is intriguing. Had to get Notebooks right away. Please continue posting your findings to linking these apps. I use Devon daily for the collection side but would like to turbocharge the word massaging side.

2 Likes