Can JXA Do More Than AppleScript?

Other than syntax differences and possible performance differences, can JXA do substantially more than AppleScript in way of how much you can automate apps and the possibilities at your disposal? Thanks!

In the end, by calling ObjC functions through a foreign functions interface (with a syntax that is hardly 'English-like' or 'user-friendly'), almost any script that can be written in JavaScript for Automation could also be written in AppleScript.

The poverty of AppleScript's native libraries however, (no built-in Regex, for example) and the fragile intractability of its 'records' – no introspection to allow us to find out what keys a record has, and an error thrown if we try to access one that doesn't exist, mean that in practice AppleScript can end up being less productive and clumsier to write.

One constraint of AppleScript which is hard, in reality, to escape, however, is that of scale.

Large AppleScripts typically start to intermittently error as they get pass the 1000 line zone. Deeply recursive scripts soon exhaust stack and fail.

Applescript is absolutely fine though, for the small and unambitious stuff, as long as you can do without basics like url encoding and decoding and regexes, and basic string, array and math functions, or are happy to learn how to call ObjC functions.

Until, that is, you want to write scripts for iOS (Omni apps, Drafts, Scriptable, 1Writer etc etc)

AppleScript can't do anything at all on iPads or iPhones, and never will be able to. Development of it has ceased.

Even on macOS, Omni app scripting interface development has all moved to JavaScript, to allow for cross-platform scripts and plugins. TaskPaper3 has for several years been JavaScript only. Some other apps, like Sketch, are also JS only.

4 Likes

Thanks ComplexPoint for the explanation! That was interesting to read/learn.

1 Like

I think the direct answer to your question is that both have the same access to Apple Events to automate apps and the macOS. So, in that sense, they are equals.

However, due to the native syntax and built-in functions, they are NOT the same.
IMO, JXA has the clear advantage.
JXA is also much easier to learn than AppleScript, in spite of Apple's claim that AppleScript's "English-like terminology" makes it easy to learn.

So, for those that don't have much experience with either, I recommend JXA.

For a more detailed discussion, please see:

Comparing JavaScript for Automation (JXA) and AppleScript

3 Likes

Thanks JMichaelTX for the response & info! :slight_smile:

1 Like