JXA and AppleScript followup

Is there a statute of limitations on blog post followups? I’ve been meaning to write a continuation of my last post for at least four weeks, but between work, the NBA playoffs, and just general laziness, I haven’t gotten around to it. Today, I settle all family business.

First up is the question of what to call AppleScript constructs like this:

… get the name of every process whose visible is true

According to Apple, this is a filter, which was one of my guesses. It’s a serviceable name but dull. I got more interesting names from readers.

Both of these are a good fit, but I’ll probably stick to filter because it’s the official nomenclature and is therefore easier for other people to understand. Still, it’s good to be reminded how all languages overlap.

Next, we move on to whether JavaScript for Automation (JXA) is worth getting into at all. Do AppleScript concepts really translate well to JavaScript? The same day my last post was published, Rosemary and David released their Automators episode with Daniel Jalkut. While discussing Daniel’s FastScripts app, they had a little sidebar about JXA. Daniel doesn’t think much of it. “It just shouldn’t be there” was his most pithy comment, but he also mentioned an “impedance mismatch” between the JavaScript language and the AppleScript infrastructure underneath it. Exactly.

And in the same email where he suggested “query,” Hamish was even more blunt: “As to JXA, that POS was DOA.”

Finally, let’s talk about the reason I’ve used JXA for some scripts: JavaScript has a good regex engine and AppleScript has none. I should have mentioned that Daniel’s latest update to FastScripts—even the free version—comes with a set of AppleScript commands for regex and other text processing. I had read the announcement, but I hadn’t yet tried it out, so it slipped my mind. I have since given it a whirl, and its syntax is a good fit with AppleScript. That may sound like damning with faint praise, but it isn’t. When you’re writing AppleScript, you want things to feel like AppleScript. FastScripts’s text processing commands do.

Now that I’ve gotten this post out of the way, maybe that will break the logjam. But don’t hold your breath.

  1. In fact, you can use where as a synonym for whose in AppleScript.