Devonthink: Possible to Hook to New.... GROUP?

Hello.

I’m trying to hook a new Omnifocus task/project to a new DevonThink Group in a database, without so may clicks.

Is there anyway to do this native in Hookmark? If not, I’ll start looking at Keyboard Maestro or indexing DT in the finder, which may be a solution.

Thanks!

talundbl

1 Like

Thank you for contacting us, @talundbl .

Current Devonthink3’s Hook to New Script is to create a RTF record. You can modify it to create a group instead.

Here is a script you can used to replace the current New Item Script of Devonthink3 (Hookmark preferences window ->Scripts->Devonthink3->New Item):

Summary
tell application id "DNtp"
    set newItem to create record with {name:"$title",  type:group}
    set refURL to reference URL of newItem
    set itemPath to path of newItem
end tell
open location refURL
get refURL

Thank you

3 Likes

Hi I’m just following up on this again.

Is it possible to have multiple different “hook to new” options for devonthink?

For example, one “hook to new Devonthink note” and one “Hook to new Devonthink Group”?

Actually, it’d be great to have two different Omnifocus options too: one for “Hook to new task” and one for “Hook to new project”

There’s only one Hook to New script per application. I don’t expect this to change. I suppose one could modify the “new item” script for any app and for it to pop up a window asking for the type of item to create; but that would be up to the user at this point.

Just in regards to this, in Devonthink you can set it so that when you choose Devonthink in the Hook To New menu, it offers you a pop up list with everything in Devonthink’s Template Folder. Anything you pick from the pop up list will be hooked to your original item (and tagged, should you so choose). This includes any file type Devonthink supports, including groups.

In case you’ve never found it, in Devonthink, go to Data>New From Template>Open Templates Folder. Every item in that folder will appear in the pop up list. You might want to delete all the templates you never use, for simplicity’s sake.

Once there, you need to create a template group. Its a bit odd, but simple. In Finder, create a new folder, and call it Group. Then open the folder and create another folder, and call that Group as well. Then go back to the original folder, and rename it so that it has .dtTemplate at the end.

Now when you pick it from the list, it will create all the items in the Group.dtTemplate folder, which is just a single group. The group will be renamed to match whatever Hookmarks gives it.

As for the Hookmarks code, replace the default Script in Hookmarks with the below. Note that you have to match the path to Devonthink as per your install.

set thePath to "/Users/[INSERT 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 the tags of newItem to "Project Support"
	set refURL to reference URL of newItem
end tell
open location refURL
get refURL

I cobbled this together with superglue and string, if anyone can improve upon it, that would be awesome. But it works.

You can also change the format of the title and the tag if you wish, this is just what I use.

The downside to this is that the list if offers you is a simple list of every item in the templates folder by full file path. So its not pretty, and once you get above about 15 items its hard to spot things. But it works for me.

2 Likes