stackoverflowuser stackoverflowuser - 1 year ago 137
AppleScript Question

Can AppleScript now be replaced with JavaScript?

I have a book on AppleScript that I'm wondering whether I should keep. I already know JavaScript.

I understand that Apple added JavaScript scripting support into OS X recently.

Does this mean that I don't have to learn AppleScript anymore to do scripting for OS X apps, or is it more to it than this? Your thoughts would be appreciated.

The above question is from the perspective of the app user who wants to make the app do things automatically.

How are things with respect to the app developers (Cocoa)? Can they get away with not learning AppleScript if they want to make their apps scriptable?

Update: Added bounty. Question rephrased (no disrespect meant towards AppleScript and its users): Given that I already know JavaScript, is there any good reason I should learn AppleScript anymore? Your detailed thoughts on this matter would be appreciated.

foo foo
Answer Source

Can AppleScript now be replaced with JavaScript?

For trivial stuff, probably. Beyond that, probably not.

  1. Too many Apple event/OSA features are crippled, broken, or missing entirely in JXA. It works up to a point, but beyond that you're stuffed. For serious or production work, when needing features that JXA screws up, or when dealing with applications that make JXA run away and cry, you will have to stick with AppleScript: it's the only currently supported solution that actually does this stuff right.

  2. You still need to understand how application scripting works, for which you'll have to read the AppleScript literature. JXA's own documentation is pathetic and misleadingly wrong, so you'll be none the wiser from reading that. There's no 3rd-party JXA literature that explains the concepts, and any that does appear in future is likely to be misleadingly wrong too. (Heck, even the current AppleScript books tend to fudge/lie/get it wrong.)

  3. You also need to understand how to script specific applications, and application dictionaries are notoriously incomplete and insufficient on their own. Which means you're reliant on supplementary documentation (if any exists), sample scripts, and more experienced users of those applications. And all of those are AppleScript-based, so you'll need to know some AppleScript in order to understand and communicate with them.

  4. App developers should continue to develop and test their applications against AppleScript - it is the de facto specification against which all scriptable applications have been developed and tested over the last twenty years, and this will continue to be the case. Even if JXA wasn't such a sack of knackers, devs would still need to test against AS just to be sure they've not overlooked any quirks there.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download