Appending text from draft to a current Devonthink note?

Hi all

I did search the forums here (and googled) but surprisingly didn’t find much info so posting here to try and solve this :slight_smile:

I want to create a drafts actions to keep sending any thoughts I capture to 1 md note in DT.

I found here in this forum and old (circa 2018) post which seems to use this syntax which I used:

x-devonthink://x-callback-url/append?uuid=x-devonthink-item://B9C35634-FECB-4315-ADD2-C23131F38FFE&text=[[draft]]

this seems to work but doesn’t actually append anything to the markdown file with the above ID

why am I doing wrong? any causes anyone?

thx a lot!

Z

x-callback-urls are only supported by DEVONthink To Go (due to lack of automation tools of iOS in the past). AppleScript is recommended on the Mac.

Or JavaScript :innocent:

1 Like

thx guys I see. since I only know how to use x-callback-urls, does any one have a AS/JS example for this?

thx a lot

PS. this does seem to work on the Mac:

x-devonthink://createmarkdown?title=[[display_title]]&text=[[draft]]

I assume that’s not x-callback-urls but rather something else?

thx

Z

It’s not a callback URL because it does not return anything. It’s just an URL command.

In Draft, you’d do somethink like this

/* get text of current MD document - check Draft's documentation
something like this:
 const txt = draft.processTemplate("%%[[draft]]%%")
*/
const app = Application('DEVONThink 3');
const rec = app.getRecordWithUuid("B9C35..."); /* use your record's UUID here */
rec.plainText = rec.plainText() + txt;

This whole thing has to go into a Draft action (if that’s the word) that you can run from any currently open MD document. Note I did not test this code! And you have of course first have to get the text of your current Draft document’s text. But that should be easy.

Thx so much @chrillek , this is a great starting point and ill use it to start exploring 'JS`!

thx alot

Z

As noted in the Help > Documentation > Automation > URL Commands section…

thx @chrillek

finally had some time to get back to this. I can’t see, to get it to work though

this is the current state of the code

/* get text of current MD document - check Draft's documentation something like this:*/
const txt = draft.processTemplate("%%[[draft]]%%")
const app = Application('DEVONThink 3');
const rec = app.getRecordByUuid("B9C35634-FECB-4315-ADD2-C23131F38FFE"); /* use your record's UUID here */
rec.plainText = rec.plainText() + txt;

when I run this I get an error

it seems line 3 is the one with const app = Application('DEVONThink 3');

why am I missing here?

thx again @chrillek !

Z

Apparently Drafts does not use Apple’s scripting technology, so Application is not known inside Drafts.
I’m away from my desktop, so can’t explore further. You could check if Drafts provides for execution of shell scripts. Then you could run the JavaScript through osascript in the shell.

Are you creating separate notes to append to a Markdown document in DEVONthink?
Or are you adding to an existing Drafts file and replacing all the text?

thx guys!
@BLUEFROG , yes I want to append the text in a current draft to an existing md note in Devonthink

ideally I could get a popup to choose which file in Devonthink but if not I can also live with a predefined md and just create a bunch of drafts actions to send to specific files

thx a bunch

Z

May I ask why you’re even using Drafts for this purpose?

1 Like

In fact, Drafts provides shell functionality like described here:

So it would be possible to write a script (AppleScript or JavaScript) that could

  • retrieve the current Drafts document’s content
  • get the list of groups from DT
  • present that list to the user to select from
  • get the list of records from that group
  • present that list to the user to select from
  • append the Drafts document to the selected record

Give that script the appropriate she-bang line and Drafts should be able to run it.

While it’s feasible, I’m wondering if it’s worth the effort. How often do you need this functionality, and why do you need it in the first place instead of simply editing the record directly in DT?

If I got you right and you want to append notes written in Drafts to exactly one note in DEVONthink why not give the notes a marker like a tag or a special part in the name which lets DEVONthink detect them and have Smart Rule/script add them to that note?

And if you used a Markdown app that unlike Drafts uses actual files and not a locked database you could handle this completely different. Simpler, that is.

thx @BLUEFROG

well mainly to quick capture stuff on the watch (via dictation) and on the phone which is very convenient with drafts

thx

Z

thx @suavito !

this gave me some food for thoughts and I started playing with implementing this using obsidian instead of Drafts since as you said that uses proper .md files.

but Im running into issues…

first to get it into Devonthink I have tried using hazel to auto move any .md file to Devonthink based on the availability of the Devonthink tag and moving that file to a auto import to Devonthink folder I have on the mac, sadly this dosent seem to work

and here is the page section of the .md file

---
tags:
- devonthink 
status: 
rating: 
location: [0.0,0.0]
counter: 
---

Also it seems like even if I do get it to import to Devonthink, I cannot seem to find in the Devonthink rules any option to append to a current file

is that possible or did I misunderstood you?

thx again

Z

There is no smart rule action to append to a file. Scripting is the only option in this case.

There are different ways to handle what you want to achieve. And a Markdown app that has an open file system (like Obsidian) offers just more options. Or to put it another way: With apps that have locked content you have to find solutions for problems which simply do not exist with apps using an open file system.

Let’s see what you could do (no claim for completeness here):

  • An app saves a note to a fixed place. Could be the DEVONthink Inbox or any Finder folder. A Smart Rule in DEVONthink handles the note—Hazel is not needed here. (With Drafts you could also send directly to a group, but remember: No batch send is possible!)

  • To trigger the Smart Rule the note must have some kind of marker. This could be a tag or a unique part in the note’s name or something else. It would also be possible that the folder (or with Drafts: group) it has been saved/sent to already is the marker as that folder is used exclusively for content that gets added to your “Big Note”. In that case you should not use the Global Inbox as you would block it for any other content.

  • The Smart Rule must, as @bluefrog pointed out, use a script. The script could add the content of the new note(s) to the end of the Big Note and delete the new note afterwards.

  • Since DEVONthink has file transclusion the script could also just add a transclusion link (if that’s the proper term) to the end of the Big Note and keep the smaller ones.

  • When you use a Markdown app that uses an open file system instead of importing the notes to DEVONTHINK you could make DEVONthink index the notes folder of the Markdown app instead. No moving into a DEVONthink database necessary.

  • If you did that you could again use a script that adds the content to the Big Note.

  • Or you could use a Script that adds just a transclusion link.

  • But what you could also do is just not create smaller notes which get one way or the other added to the Big Note but write in the Big Note directly! Because when indexed you have access to it both in your Markdown app and in DEVONthink. It is the very same file! If navigating in the Big Note is not a problem due to its length then this would be both the most technically simple and the most efficient solution I’d say.

But that is of course up to you and how it fits your workflow.

2 Likes

thx @suavito !

Z

I have a similar requirement to you @zeltak and I am just trialling DT3 to see whether it works for me

Does anyone have any examples of a script to append the text to a text file in DT3