Execute Drafts JS Code from AppleScript

Is it possible to run code inside Drafts from Applescript or JavaScript For Automation ? I am thinking along the lines of TaskPaper .evaluateJavaScript method. If that is not currently possible, I think it will bring many possibilities.

For example, perhaps running this code in Script Editor:

Application('Drafts 5').evaluateJavascript(`
(() => {
    'use strict';

    const d = Draft.create()
    return (
        d.content = s,
        d.update(),
        d
    )
})();
`)

@agiletortoise, is it possible to return values from AppleScript ?

It is not currently possible to run code in Drafts from AppleScript in the way you describe. Drafts incoming AppleScript support is very limited at the current time.

Yes, it is completely possible to pass any parameters you desired from Drafts to AppleScript and get return values. See AppleScript docs for examples.

1 Like