JXA quick guide?

So I have a lot of experience writing bare javascript code.
And I begrudgingly have a lot of experience writing applescript code.

I’ve been playing around writing AS in JS in the editor when I’m doing little tests and every time I say to myself OMFG YES THIS IS HOW A SCRIPTING LANGUAGE IS SUPPOSED TO WORK. Like “string.split(”|“)” instead of “set applescript’s text item delimiters to “|””

So anyway, I’m well positioned to make a quick transition, I just need a little help getting started. Like literally, how do you do the run handler? And the open handler? Basically everything that is applescript specific.

For what it’s worth, I don’t even like Javascript. But compared to Applescript native syntax, i LOVE javascript :smiley: And writing AS in JS, I’m confident will let me to a lot more, a lot easier.

There are definitely parts of JS that are more powerful than AS. However, JS doesn’t have named parameters, which is a barbaric approach.

The JavaScript part seems to work OK, but the Apple Event part (the “Automation” bit) is half-baked at best. I had very little luck with it for anything but simple stuff; good thing I don’t like the language either (I much prefer Ruby). The Objective-C/Cocoa bridge seems to be better, but unfortunately JXA wound up being just another nail in the coffin for the Automation team.

Here is a series of books that include many useful tips and scripts for developing with JavaScript for Automation (JXA). The focus is primarily on connecting applications (Safari, Pages, Keynote, BBEdit and more) rather than pure automation, though automation techniques are also covered. The seventh book in the series has just been released.


JavaScript for Automation: Crafting Scripts for macOS

This practical guide introduces JavaScript for Automation (JXA), a versatile scripting language for automating workflows on Mac devices. Seasoned scripter Jesse Shanks leverages JXA’s tight integration with macOS to eliminate repetitive tasks, manipulate data, connect apps to boost capabilities, and customize productivity scripts.

View on Amazon


JavaScript for Automation 2: Supercharge Your Mac with ChatGPT

A comprehensive guide that transforms your Mac experience through the power of automation. This book teaches technical skills while inspiring imaginative uses of automation to streamline workflows and bring more joy to the macOS experience.

View on Amazon


JavaScript for Automation 3: More Interesting and Useful Scripts

Whether you’re streamlining your workflow, enhancing your coding skills, or exploring the fascinating world of JXA programming, this book provides practical guidance to help you achieve more with your Mac.

View on Amazon


Javascript for Automation 7: Scripting the Next Generation (Aquitaine Programming)

Whether you're a curious coder, a seasoned scripter, or a Shortcuts power user ready to go deeper, JavaScript for Automation 7: Scripting the Next Generation is your hands-on guide to building next-level scripts that make macOS smarter, faster, and more connected. This isn’t just another automation manual — it’s a deep dive into scripting conversations between apps, combining JXA with Shortcuts and Cocoa-powered user interfaces to create seamless, expressive workflows across macOS.

View on Amazon

--Jesse Shanks, aquitaine publishing

1 Like