Comment by saagarjha

6 years ago

> look at the AppleScript documentation and translate the code to JavaScript syntax

Yeah, I can’t do this. It’s non-obvious to me how it translates until I actually stumble upon the correct thing.

AppleScript looks fantastically simple and easy to pick up until you actually come to write some. Then, because of the "conversational" structure of it, it feels more like guessing the right magic incantation than programming.

It certainly reads nicer to non-programmers, but I feel like writing it requires just as much learning as any more "traditional" scripting language, so I'm not really sure what the benefit is.

  • I'm more of a hobbyist than a professional programmer, so take that for what you will:

    I really like Applescript. I agree that it's harder to write, and especially harder to write well, because functional Applescript won't necessarily come out as english sentences, if you aren't careful to construct it the right way.

    But the enhanced readability makes it worthwhile. I love that I can look at my own Applescript code and just read what it's doing in english.

    I actually wish I could do more with Applescript than just Mac scripting. I've been thinking for a few years now that I ought to play around with Hypercard, but PowerPC emulators are a pain to get running. There's a modern clone called SuperCard, but it costs $200...

    P.S. The "open dictionary" option built into the Script Editor is helpful for finding the right "incantation".

  • I think it requires more. I have a deep respect for anyone who can figure out how to write AppleScript, because I sure haven’t figured it out even after being able to pick up most “traditional” scripting languages quite quickly.

Funny enough, back when the Mac Automation devs were still getting JXA ready to throw away, one of the things I told Sal Soghoian to do was to add automatic AS-to-JS syntax translation to Script Editor’s Log pane. While it only translates outgoing Apple events, not native AS code, 99% of the time JS users already know how to write general JS code, and it’s the application-specific references and commands they’re struggling to form.

Back when appscript was still a thing I hacked together a quick-n-dirty AppleScript-command-to-Python/Ruby/ObjC translator app which appscript users absolutely adored, plus it greatly reduced the number of “How do I…” support questions because, more often than not, users already had a working example in AppleScript which they could just run through the translator to get the answer for themselves.

Needless to say, Sal Soghoian completely ignored my expert recommendation for this killer feature which could be implemented in a day, choosing instead to dump JXA and its few hapless users down the same black hole of nothingness as all his other product failures. PEBKAC. Not Invented Here. So it goes.

--

[edited to add]

Just d/led the JavaScriptOSA zip from the appscript project page on SourceForge, and the bundled JABDemo.app still works. It’s not codesigned so you’ll have to right-click the app to Open it, overriding the security warnings, but it still works even on 10.15 (caveat any bugs in the underlying JavaScript Apple event bridge, of which there were a few, plus the endless string of permission requests whenever you try to control another app). Example:

Original AppleScript commands:

    tell app "textedit" to get name of document 1

    tell app "finder" to count every folder of home whose name begins with "D"

Generated JavaScript equivalents:

    app("TextEdit").documents.at(1).name.get()

    app("Finder").home.folders.where(its.name.beginsWith("D")).count({each: k.item})

I mean, I wrote the thing and even to me years later it’s still like freaking voodoo! :)