Is it a good idea to learn JXA in 2022?

Heck, it wasn’t a good idea to learn JXA the day it was released in 2014! It was crippled and buggy then, with lousy documentation and no official or community support worth a damn.

JXA hasn’t changed since, partly because the Mac Automation team were lazy and disinterested, mostly because Apple finally realized this for itself and disbanded their department in 2016, reassigning its developers to other teams and sacking the manager responsible.

The entire Apple event/Open Scripting Architecture/AppleScript stack has been mouldering in maintenance mode since (its only growing market nowadays is iin malware). A huge pity too because Apple event IPC, if a bit crusty, is legitimately awesome—vastly superior technology to anything Shortcuts or any other platforms offer. It’s just been murdered by Apple repeatedly shackling it to garbage and then leaving it to rot. (I actually fixed that problem 15 years ago, until the Mac Automation team wrecked it again. Still salty.)

FWIW, I doubt Apple will pull JXA before they pull AppleScript as well. They should have deprecated Automator, JXA, and other no-longer-wanteds in macOS 11 as part of their proactive slimming down of legacy scripting language support (Python, Ruby, etc) in their overall transition to Shortcuts, but they simply don’t care enough to be bothered. (Alas, the post-Jobs Apple cares little for quality/trash control.)

Meantime, Adobe’s made clear that the future of InDesign/Photoshop/Illustrator automation lies in its next-generation UXP JavaScript engine. That’s going to be massive so once the print industry realizes this and starts migrating from AppleScript to UXP, that’ll be the end of AppleScript’s last legitimate market and Apple is then free to pull its plug quietly without any upset. (3–5 years would be my estimate, depending on the speed of these behemoths.)

If you want something that works right and is still “officially supported”, stick to AppleScript. The language itself is terrible, but the application automation stuff works perfectly and, crucially, AS still has a small but experienced user community to help you out whenever you get stuck.

As you’re a web dev, you should already be using Node.js for all your general day-to-day scripting. Keep on doing that. Node has its own share of issues, but as a platform it’s unbeatable.

You can call into AppleScript from Node via the command-line osascript for simple tasks, passing arguments and results as plain strings (or JSON at a push). Slow but simplest. If you are brave and need deeper/faster integration, the AppleScript-ObjC bridge should be accessible via Node’s objc bridge, allowing you to pass complex values and call multiple AS handlers directly.

The other option, if you’re even braver still, is to go all in on Node and use nodeautomation which, unlike JXA, works about as well as AppleScript. Caveat emptor: no warranty or guarantee of fitness and I do not provide [free unpaid] support, but as long as I need nodeautomation for my own work I will continue to maintain it. Its documentation is not great (still better than JXA’s though) and the accompanying ASDictionary and ASTranslate tools answer most of the practical “How do I…” questions when translating application commands from AppleScript to the equivalent JS syntax.

Whichever way you go: The key to understanding Apple event IPC automation and using it effectively is realizing it is not OOP; it is RPC plus simple first-class relational queries! The IPC system’s design and much of its behavior derives from SQL and RDBMSes, only manipulating a tree-like data graph instead of rectangular tables. If you assume it is DOM and try to treat it like that (as JXA wrongly did) you will only confuse and frustrate yourself, and your code’s performance will likely suck.

There’s some explanation of this in the nodeautomation documentation (AppleScript’s docs totally ignore this and JXA’s are outright misleading). For a more general understanding of the “Why?”, Dr William Cook’s paper on AppleScript’s development is a proper good eyeopener.

HTH, sympathies, and good luck.

2 Likes