Automate sending Drafts to Notes on Mac

I am happy with an AppleScript in a Drafts action (see below) that creates a Note for me. I can run it on a single draft or multiple drafts just fine.

What I wish to do, now, is have this action run automatically (I can schedule running in Keyboard Maestro, for example)…

  1. Against all drafts in the inbox…
  2. Finding only drafts with a certain tag

Why? Drafts on my Apple Watch is the best way for me to capture text, but I ultimately want these to go to my Notes app. Fewer manual steps are preferred, thus my request for help with the automation part.

Can anyone help?

Thank you,

John


on execute(draft)
set theText to ""
set theText to content of the draft

	tell application "Notes"
		set Note_Body to "<pre style=\"font-family:System Font;font-size:14px;\">" & theText & "</pre>"
		tell account "iCloud"
			make new note at folder "Notes" with properties {body:Note_Body}
			delay 2
		end tell
	end tell
end execute

You could trigger opening a URL in Keyboard Maestro that will run the action.

You could trigger your desired selection through additional key strokes sent from Keyboard Maestro to Drafts, or you could expand upon your action (utilising JavaScript) to work over the desired set. The latter would forego the usual timing challenges and be more robust in my opinion.

Hope that helps.

Yes. A more complete script solution is the better option. Are you aware of any examples (or better yet, similar solutions), here?

No. AppleScript is still relatively new, so I don’t recollect seeing anything obviously similar.

But the gist would be use Draft.query() to get the matching drafts. Iterate over the array of Drafts it generates, each time calling out to a revised version of your script embedded in the JavaScript.

So that’s a combination of a query, a for loop over the query results, and in the for loop a run of the AppleScript for each item (draft).