Yosemite Javascript for Applications (JXA) actions?

What is the best way to execute actions which use Yosemite Javascript for Applications (JXA) ?

So far I have tried:

1.’ Execute Applescript’ actions with plain text and compiled script (JXA still uses the extensions .applescript and .scpt in OSX 10.10 Script Editor
2. Shell scripts calling the osascript command

With the latter (presumably the more hopeful approach) I have tried the -l language script with ‘jxa’ and ‘javascript’, but that doesn’t seem to be what is required.

Any thoughts ?


man osalang and the osalang command itself reveal that JavaScript needs to have those two capital letters.

commands like:

osascript -l JavaScript '/Users/houthakker/Desktop/clipappend.applescript'


osascript -l JavaScript '/Users/robintrew/Desktop/clipappend.scpt'

Do run script files containing textual or compiled JXA javascript, despite provoking a retort like this:

2014-11-09 16:27:27.644 osascript[7530:562983] warning: failed to get scripting definition from /usr/bin/osascript; it may not be scriptable.

1 Like

You can execute a JavaScript for Automation script from Keyboard Maestro like this:

Like AppleScript, it is executed within osascript, and thus has limited UI context.

You can also write a shell script like this:

#!/usr/bin/env osascript -l JavaScript
console.log( "Hello\n" );

Make it executable, and Keyboard Maestro can execute that as well.

1 Like