Creating Hook to New item in Devonthink while retaining links

I love the Hook to New feature in Hookmarks, as I can create support materials straight from a project in Omnifocus, avoiding a lot of manual steps. However, I use Devonthink, and if you create a new item and then have it imported into DT, it loses the hook (since Devonthink essentially makes a copy then destroys the original instead of just moving it).

There’s also the downside that you can only have one set of Hook to New scripts per app in Hookmarks (afaik) so it would only support one type of file anyway. I like to use mindmaps, markdowns, kanbans, spreadsheets and so on, according to my need.

A workaround I’ve come up with is to use Applescript to create a new item based on the templates folder in Devonthink. I’ve then populated my templates folder with all the various document types that I might want to link to Omnifocus.

When you run the Applescript it offers you a pop-up showing you your Templates. You then choose the relevant template and it will create the file, rename it and Hook it.

set thePath to "/Users/[Your User]/Library/Application Support/DEVONthink 3/Templates.noindex"
tell application "System Events"
	set templateList to {name, POSIX path} of every disk item of folder thePath
end tell

tell application id "DNtp"
	set theTitle to "$title"
	set theTemplate to choose from list templateList's item 2
	set newItem to import template (theTemplate as string) to incoming group of current database
	set name of newItem to theTitle
	set refURL to reference URL of newItem
	set itemPath to path of newItem
end tell
open location refURL
get refURL

Limitations

  • I have no idea what I’m doing with Applescript and just fudged my way through the above. If you, dear reader, can retype this script more succinctly, that would be very welcome.
  • Just shows you the path and filename of each template. A nicer list of templates would be great.
  • This doesn’t permit you to put any content within the file itself, as currently happens with the rtf and md files. No idea if that’s possible.
  • The list of templates won’t work recursively down into any sub-folders. This is possible, I just haven’t bothered to do it yet since I don’t use enough templates to make it worth it.

With thanks to this post on the DT forum Creating new file from template folder by AppleScript - Automation - DEVONtechnologies Community

3 Likes

Hi,

I don’t know if this fits your purpose, but here’s what I do.

I “hook to new ” and use Hazel to monitor my Hookmark folder for new files. Hazel then moves them directly to DEVONthink via the DEVONthink Finder Inbox. It works very well for me and allows me to save anything to DEVONthink quickly.

1 Like

And presumably Hazel automation copies the hook://file/ link to a given file (“foo”), and then when you create the new DEVONthink item (“Bar”), you get the items hooked to foo (items which have that URL) and then you hook Bar to everything that foo was hooked to, so you preserve your hooks.

Hmm, that doesn’t work for me, When I try to use Hazel to move & import to Devonthink via the Inbox in Finder, it breaks the link and I have to manually hook or rehook it.

Ok. The only thing else I do differently is after Hazel moves the file, I close the original instance and reopen from DEVONthink directly. Maybe that will make a difference?

I tried that with no joy, sadly. Which folder specifically is Hazel monitoring? And are you using indexed folders in devonthink or a database?

So, I have Hazel monitoring the folder whose filepath is:

/Users/< username >/Documents/Hookmark/notes

The action Hazel performs is to watch for when “kind is Scrivener Project” then “move to folder Inbox (which is the DT Finder inbox.)”

I have also used this for other file types, and have altered it to watch for parameters other than file type (e.g., tag, date added.)

My DEVONthink is a database rather then indexed folders.

Ok something occurs to me, if you go inside Devonthink to the imported file and launch Hookmarks, can you see the original linked file? Or can you only see the file in Devonthink from whatever the originating file was? ie is it only working in one direction?