Devonthink - Hook to New...RTF?

Hi - I’m interested in Hook primarily to create links between Devonthink files and notes relating to those files. The “Hook to New…Devonthink” command is fantastic, but I would prefer my files to be RTF, rather than TXT. Would it be possible to add this functionality? Thanks!

1 Like

welcome to the Hook Productivity Forum, @jenniferc

In Hook > Preferences > Scripts > DEVONthink > you can replace the New Item DEVONthink script with:

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

i.e., change the “type” field to rtf, and add rich text:" " because DEVONthink requires that per: Error calling create record with {type:rtf} or {type:rtfd} - DEVONthink / Automation - DEVONtechnologies Community.

At some point, Hook should allow users to specify multiple “New Item” scripts per app, so that for a given app, you can choose using a pulldown menu which Hook to New script to use.

1 Like

Thank you, @LucB, for your swift answer.
I am in serious doubt, if my closely related suggestion deserves to become an independent thread.
I was thinking of exactly the same minor improvement as @jenniferc, but, apart from the RTF format, surely useful for many, I was thinking of having the additional option also of the MD format (if at all possible expanded), to be used with the resurected MultMarkDown Composer, which I really like.
Of course, the user majority might very well continue to prefer the TXT format, but why not have more choice?
So, my question, @LucB, is the following: would it be possible in
Hook → Preferences → DEVONthink either

[li]to set a default format for (any) newItem; or[/li]
[li] (if no such default format is set) then ask, whenever a newItem is about to be created, whether one wants for this particular new item: [ul]
[li]the TXT format; or[/li]
[li]the RTF format; or[/li]
[li]the MD format (hopefully expanded)[/li]
Do you think, @LucB, that such a script would be too difficult to create? Many thanks for considering this.

Thanks for asking, @adrian. Yes that should be possible and not too difficult. Hook currently offers an interactive script for Apple Notes. It presents a dialog box.

Internally, I recently requested an interactive script for Apple News. The reason we don’t have a built-in script for Apple News is that Apple News (sadly) does not have an API. We can get the URL of the ‘news’ item via UI Scripting, but Apple does not expose the title. (Honestly, Apple disappoints.) So we would prompt the user to enter a title for the news article, which they might have pasted in the clipboard. We’re not sure if that is what we should do. But I thought I should mention it in this context. (Also to get a bit of feedback.)

Why does none of the BBCode alternatives for lists writing function here? A bit frustrating.

Yes, @LucB, I think prompting the user to give a title to an AppleNews article, is, in fact, not a bad idea at all, as one could already then organise one’s material ans one pleases; what sums up the article best for the initial author (or for the editor, or for the the publisher) and which becomes the original title, might not at all be the most truthful way to label the same article in one’s personal view.
Talking about AppleNews, @LucB: do you know NetNewsWire? Brent Simmons and his collaborators are wonderful people, and, I guess, you would very much einjoy working with them. Just an idea.

1 Like

This is fantastic! Thank you, @LucB - and doubly so for responding so quickly. If I may make one more request - would it be possible to add a line to the script so that the new RTF (or text, or markdown) file is created in the same Devonthink group as the file to which it is linked? Thanks in advance for any assistance you can offer this non-script-savvy user.

1 Like

We would need to dig into the DEVONthink API for that. It would be doable if DEVONthink’s automation interface supports it. The trick would be to use the Hook’s $user_link variable in the New Item script for DEVONthink (in Hook > Preferences > Scripts > DEVONthink) — that variable resolves to the URL of the source resource that the new item will be linked to. (Hook to New creates a bidirectional link between a source and a new item). I suppose the script would need to

  1. check that the source scheme (i.e., of $user_link) is DEVONthink://
  2. ask DEVONthink (via API) what the group of the item at that URL is.
  3. after or while creating the new record in DEVONthink, ask (or specify to) DEVONthink that the new record should be in the same group.

Our DEVONthink dev is not currently available. Someone else on the forum who is more familiar with DEVONthink’s automation might be able to fill in the blanks or suggest an overall improvement — perhaps someone here or at DEVONthink.

I don’t know if we would want this to be the standard DEVONthink strict. I.e., I don’t know how widely people would want this, and we’d need to ensure it’s not brittle. But we can share it here on the forum for use. (Ideally alternative behavior would be user selectable without users needing to paste in code from the forum.)

Thanks again, @LucB! I will try posting in the Devonthink forum to see if someone there can help, too.

1 Like

version 132 of Hook’s integration scripts make RTF the new default for DEVONthink, as we now think this is the more commonly desired option. The other features, auto setting the Group and supporting multiple ‘hook to new’ options are still pending as they require updates to the Hook app, and we’re working on a collection of other features.