JXA, AppleScript or URI scheme to trigger the "New from Clipboard" function?

Wondering if there’s a simple way to script the function “New from Clipboard” ? (I’d like to integrate this into an Alfred workflow)

Using Acorn 7.4.4 non-MAS version.

Thanks for any tips!

I poked around and came up with this. It works! Is this the “right” way?

function run(argv) {
  const Acorn = Application('Acorn');
  Acorn.activate();
  const doc = Acorn.makeNewDocumentFromClipboard();
}

That’s a valid way!

It looks like it’s sending valid Apple Events to Acorn, using its published AppleScript dictionary. You could also do the following:

osascript -e 'tell application "Acorn" to make new document from Clipboard'

But what you’re doing is completely valid, and I personally like better.

It’s also possible to send snippets of JavaScript to Acorn to run in a similar way.

-gus

Great. Is there a repo somewhere with some sample scripts? I’d love to see some other examples of what’s possible.

There’s a bunch of plugins that’ll show up under the Filter menu here:
https://github.com/ccgus/AcornSDK/tree/master/jstalk

And our docs have some here as well:
https://flyingmeat.com/acorn/docs/example_applescript_and_javascript_scripts.html

Our release notes have some various examples if you search for “JavaScript”:
https://flyingmeat.com/acorn/releasenotes.html

And even though the delegate(). makeNewDocumentFromClipboard() isn’t a public API, the following will work:

tell application "Acorn" to do JavaScript "acorn.delegate().makeNewDocumentFromClipboard();"

You can also send a file path to a JavaScript file to open up.

Good stuff, thank you @ccgus :pray: