JavaScript for Automation (JXA): What's supported? and Workarounds

So, are you saying that the JXA compatibility IS the same as the Safari compatibility?

No.

  • There is an SF9 version of the JavaScript Core Interpreter (ES5+)
  • There is an SF10 version of the JavaScript Core Interpreter (ES6)

Which one of those you can use with the Automation object in Script Editor and osascript depends not on which browser version you have installed, but on which of them (SF9 JS or SF10JS) is installed as the system JavaScript Core interpreter, and compiled into that system’s versions of Script Editor and osascript.

El Capitan uses an SF9 JSC in Script Editor, osascript, Bash jsc (regardless of which Safari is installed)
Sierra uses an SF10 JSC in Script Editor, osascript, Bash jsc (regardless of which Safari is installed).

This means that:

  • Automation scripting on El Capitan is at the SF9 (ES5+) level, even if you are using SF10 Safari
  • Automation scripting on Sierra is at the SF10 (ES6) level, even if you have found a way to install and use an SF9 browser

If you want to write your own JS Scriptable app, you can use:

https://developer.apple.com/reference/javascriptcore/jscontext

The version of the JSC interpreter (SF9 or SF10) that will be available in the JSContext in your app will not depend on which browser you are running, or which browser is installed by your users.

The (JSContext + Automation object = ‘JXA’) in El Capitan Script Editor and osascript runs the SF9 JSC interpreter, even if you are running a browser which provides an SF10 JSC interpreter.

1 Like

Thanks for being so direct and succinct, Rob.

This is really the bottom line.
Thanks for providing us with the clear information to make an intelligent decision about what to use.

Since I'm running El Capitan, and do not plan to upgrade to Sierra for some time (months), I plan to stick with ES5+. While there are some cool features in ES6, I don't see anything that enables me to accomplish that I can't do with ES5. But then I'm not a power JavaScript coder like some of you guys.

@DanThomas, it's your topic, but if it were me, I'd check Rob's above post as the "Solution" for this topic.

@DanThomas, it's your topic, but if it were me, I'd check Rob's above post as the "Solution" for this topic.

Actually, I didn't indent this topic to be a question, although I can see how it could be taken as such.

What I meant the topic to be was just what my OP showed - how to use Polyfill, and how to know when to use it.