Appending text from draft to a current Devonthink note?

I outlined how that could be done in another post here

but I have neither time nor interest to write that script.

Alternatively, it might (!) be possible to access Drafts data from a script run in DT. I didn’t try that, and I’m not sure if/how that works. But Drafts seems to be offering very basic scripting support.

Actually, I’d suggest to go for another tool then Drafts if you want to write/edit MD outside of DT. Drafts’ concept to store all documents in its own silo (as well as its lack of JXA/AppleScript support) make it more difficult than necessary to interact with other applications.

Edit: It should in fact be possible to run AppleScript from within Drafts so that it can access DT’s AppleScript functions. As said before, I’m not going to go there, but here’s a link for anybody interested in exploring further:

And here’s a very simple example (stolen from the Drafts AppleScript action examples) to pass a draft onto BBEdit:

let method = "openInBBEdit";
let script = `on openInBBEdit(content)
	tell application "BBEdit"
		activate
		set theWin to make new text window
		set the contents of theWin's document to content
	end tell
end openInBBEdit
`;

let runner = AppleScript.create(script);
if (!runner.execute(method, [draft.content])) {
	console.log(runner.lastError);
	context.fail();
}
3 Likes

thx @chrillek !

Just out of curiosity: Why do you use Drafts one the Mac, @zeltac, and @nickwild too?

On iOS/iPadOS Drafts undoubtedly has its merits—although they are waning away with every improvement of the Files app (so for at least the next decade Drafts will be doing okay I guess).

Drafts on the Mac synchronizes with its mobile counterparts, all right. But what does it offer beside from that? I don’t see what it would make an exceptionally comfortable place “where text starts” (Draft’s tag line). And when just used as an inbox for the synced content from mobile devices you face the obstacles this thread is about.

Syncing with iOS is reasonable enough for me to use it.

But that aside - the main advantage of Drafts is that it has a very large set of integrations with other apps. Plus those integrations are all customizable and it is fairly easy to create your own integrations to any app which might be missing.

Turning your question around- what other Mac app integrates so easily with just about any other software destination?

They all integrate with each other quite well, if they don’t lock their content. I’d say.

But of course I understand what you mean. I’m not anti-Drafts by any means. I was actually blown away by what it is capable of on iOS. I don’t mind its not at all intuitive user interface @cgrunenberg mentioned because the way I used Drafts I would mostly see a fresh editor window to write in. And actions, sometimes activated by a simple tap on a button in the extra keyboard row, would do highly specific things once they were programmed.

Pre Files URL actions on iOS were the one way to move content from app A to B. With Files iOS/iPadOS got more open, although by far not on par with macOS. So there is still a use for highly specific, user customizable actions, even on macOS. But only as an option, not as a must. The rest can be automatized. Or better: It could be if only Drafts’ notes where not hidden in its database. Or at least if its Inbox (working similar to DEVONthink’s Finder inbox folder) had an Outbox counterpart.

1 Like

But to leave the general discussion about Drafts (for the moment?) and hopefully make myself at least a little bit useful to the OP and other Drafts users:

There is actually a simple way to append to a note available in DEVONthink with Drafts!

There is a Drafts action called Append to iCloud Journal. It once creates and then appends to a note saved in Draft’s iCloud Drive folder. Make DEVONthink index that folder. That’s it.

Of course it would not have to be iCloud Drive. They have a Google Drive action too and probably you could alter it to save locally. I only have the free tier so I can’t check if it works.

Technically then the note is not actually in DEVONthink, just indexed, but you have access to it to do whatever you want to do with it. Until someone came up with the proper Apple Script it might be sufficient.

EDIT: The Append to iCloud Journal action provides a .txt and not an md. file but that can quite likely be customized too.

EDIT II: The Append to Obsidian Journal action saves locally. Even without using Obsidian. You just have to chose the destination when using the action for the first time.

I agree it took a while for me to take a liking to the Drafts interface and its lack of rich-text support

But I realized that the user interface is unusual for a reason - it truly is efficient and also highly customizable

THe “hidden database” is not really an issue because the intent of Drafts is not to keep stuff there long-term; it is a tool to send stuff off to its final destination

2 Likes

Exactly for that reason it is an issue. The user has to manually move the content to its respective destinations. That’s okay for 10 notes with 10 different destinations. But when the majority shares one destination it’s just cumbersome. No Smart Rule to ring them all… wait, I’m confusing something here…

And since Draft’s tags are not macOS and iOS/iPadOS tags, to keep them the former have to be converted to the latter. Meaning: An action is mandatory, export or share lose them. Drag & drop does not work at all. And some actions don’t work in bulk and then it gets really annoying.

Drafts on the Mac is about bringing iOS restrictions to macOS. If it had an open file system, other apps like DEVONthink or Hazel could process its content. Or if it had its own Smart Rules, Auto Actions or whatever they might be called. All of this additionally to what it can do already, of course.

1 Like

If the majority share one destination, then just create a custom action to handle it exactly as you wish.

In my view Drafts is the opposite of a smart-rule situation. It’s a quick go-to place to start typing a quick note wherever you are - at your desk or with your iPhone. From there, you have infinite options to send your note anywhere you want.

Smart-rules work best when the workflow is consistent and predictable; that’s not where I use Drafts. Drafts is for when I get a phone call that might be related to work, a friend get-together, something I am planning with my kids, or something important for my date with my wife - in other words, random important stuff that can come in anywhere, anytime. Whatever the content - I am ready to start the note in a microsecond and I can do whatever needed with the note when it is done.

This is the point we can agree on 100%. To my knowledge especially on mobile devices there is no app besides Drafts and 1Writer where the writing can start as fast (plus additional customizable keyboard row). And, like you said, the rest comes later.

Unlike me, and that’s why we disagree in some aspects.

And I want both. Drafts actions can, as you know, have an “After success” step like moving the note to the Archive. If all notes remaining in Draft’s Inbox could be accessed on the Mac from the outside or could be moved by an automatic action Predictable Me would be happy too (and if the Capture window had keyboard shortcuts for italics etc. like the main window).

2 Likes

All that said, it would come handy if DEVONthink got an Append URL command, at least for plain text based notes.

hahah agreed :smiley:

I could not resist trying how it might work.

So if you want to append to a specific note and not the current one opened in DEVONthink and if you don’t mind indexing in DEVONthink then it is quite simple to handle in Drafts. No tinkering with the above mentioned journal actions is necessary.

Just this:

You have to pick a folder when you run the action for the first time. And you have to index that folder in DEVONthink.

Please note that the tags in The Big Note.md get overwritten by the tags of the latest note appended to it. So if it has no tags at all all former tags will be gone from The Big Note.md too.

And, I guess, that folder has to be available on all systems you’re syncing with and has to have the same name everywhere.

I’m not saying that it’s not possible to integrate Drafts with DT. I just find it more cumbersome than necessary, due to the fact that Drafts insists on their own silo and foregoes Apple’s scripting technology (what they have in the scripting dictionary does not even work as expected). So one has to jump through more loops than necessary were they using a more open approach.

1 Like

If you want to have access to a file on more than one device it has to be located on some cloud drive. It works over the Finder/Files App, Draft’s action just appends to the file and has nothing to do with syncing.

Exactly. And that’s quite sad.

@suavito for me I use it as a general scratchpad (like a real world jotter)

Some notes will stop on there for the short term. A quick phone number or address that I may need over the next 48 hours

Some notes will be deleted hours after I have resolved my short term need for that information.

And some notes I will want to file away in a long term storage with ease of retrieval (DT3) I do not alway know what I will want to do with it in the future so everything goes in there for triaging without having to second guess what I may or maybe not need this for.

Ultimately nothing should remain in Drafts for me for longer than a month and I have a review process to check what is in Drafts and how I best remove it! :slight_smile:

1 Like

And if you really want to append a Drafts note to the currently open DEVONthink note as the title of this thread suggests, create a new Drafts action with one step: Run AppleScript and try this (in parts stolen) script:

-- Appends current *Drafts* note to selected *DEVONthink* Markdown note

on execute(draft)
	set theDraftsNote to (content of draft as text) & return
	tell application id "DNtp"
		try
			if not (exists think window 1) then error "No window opened."
			
			set theseItems to the selection
			if theseItems is {} then error "Please select some contents."
			
			set thisItem to first item of theseItems
			if type of thisItem is not markdown then error "Please select a Markdown note."
			
			set thePlainText to the plain text of thisItem
			
			set theSeperator to return & "---" & return -- If you don't want a seperator between the appended notes just set it to "".
			
			set thePlainText to thePlainText & theSeperator & return & theDraftsNote
			set the plain text of thisItem to thePlainText
			
		on error error_message number error_number
			if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		end try
	end tell
end execute

Rough but working version.

I use drafts EXACTLY as @nickwild does

and thus the original post was to find ways to make the forwarding to long term storage in Devonthink as easy as possible (including appending to current markdown notes at times :smiley: )

Z

1 Like

thx again @suavito!

actually what I aimed at is to not even have Devonthink “involved” :slight_smile: ie quick send to Devonthink notes from drafts without worrying which note is open and so on

I was thinking wither of a URL command (with pre defined most recent used notes in Devonthink, one per actions) or even better the sorter/move window

CleanShot 2022-04-07 at 08.20.52

thx for the very interesting discussion

Z

That’s how I understood your first posting but the topic says otherwise so I wasn’t clear what you aimed for. And I decided to deliver for both options.

Anyway, while the Apple Script is a solution for adding to an open note in DEVONthink my earlier suggestion with an indexed folder should work for you—DEVONthink will not be active until you fire it up. It’s by the way how I use other, open Markdown editors (just without the appending).