Create new Draft via JXA?

So I know we can create a new Draft via AppleScript:

tell application "Drafts"
    make new draft with properties {content: "My Draft Content", flagged: false, tags: {"blue", "green"}}
end tell

is the same also possible with JXA (Apple’s Javascript for Automation)?

Yes? JXA runs on the same runtime with Apple Events as AppleScript, so, in theory at least, anything you can do from AppleScript you can do from JXA.

As for what the incantation is to do it, I admit I do not know. I’ve never been able to make any sense of JXA syntax.

Is there a reason you need to be able to do it from JXA vs. AppleScript?

Is there a reason you need to be able to do it from JXA vs. AppleScript?

Well, I already have a JXA script, so I’d prefer using JXA rather than going some weird JXA → shell → Applescript detour or using URI Schemes, both of which have caused me various issues with escaping special characters…

Looks like the JXA equivalent is:

Drafts = Application("Drafts")
draft = Drafts.Draft({
	"content": "My Draft Content"
})
draft.make()
1 Like

thank you, that works like a charm :slight_smile: