Which scripting language?

I'm looking at the various language options for scripting in OS X, and wondering if anyone can offer any advice.


1. Python

I've tried python, and the PyObjC cocoa bridge works reasonably well. However, the bundled version of PyObjC in OS X is incomplete, ancient and unsupported. I could install the newer versions of python and PyObjC, but I prefer something that works out of the box on any Mac.


2. Swift

Again, I've had some success here, and written a few little scripts which work well. The only down-side is that Swift still seems to be a moving target, and things need rewriting every time the version gets updated.


3. Ruby

RubyCocoa seems to be installed on OS X by default, though I can't find out much documentation about it. But it's the most compelling candidate so far.


4. AppleScript.

Just No. It's Englishy-ness and lack of algebraic rigour I find awful and confusing.


Have I missed anything?

You forgot JavaScript for Automation, which is simultaneously way cool and super scary (-:

3. Ruby

Just FYI, Ruby has the same problem as Python; the version installed by default is quite old:

$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]

You seem to have two conflicting requirements here:

  • You want to use the latest stuff

  • You want your scripts to work out of the box

It’s simply not feasible to meet both of those requirements; you have to give up one or the other.

Personally I use Python (the built in 2.7.x) for most of my scripting, with a side order of AppleScript for the GUI integration stuff. For me it’s more important that my scripts run out of the box then it is for me to have the latest language and library features.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

RubyCocoa hasn't been included with the system since about Mavericks, the framework can be manually installed though. There is also the Cocoa gem (free), and RubyMotion (not free).


JavaScript for Automation (JXA) is indeed scary, and if you are looking at Cocoa-Javascript applications or scripting other applications (like AppleScript does), it is very scary. Even though JavaScript itself is very popular, Apple's implementation leaves a lot to be desired, as witnessed by the lack of followers.


Going forward, it looks like Swift may also be Apple's choice for a scripting language, as the REPL and playground are constantly being improved. I am not a pro, so something like Ruby is way easier to deal with than things like Swift's static typing and optionals (not to mention Xcode), so I suppose it comes down to how serious you are.

i script the hxll out of any flavor of Linux, or *Nix. Just use bash, sed, grep, awk. cross-platform, high-performance IO, low latency then rule the planet from the command line.


If you want to be just lethal, perl.

Don't waste your time on JavaScript for Automation: it's a buggy crippled piece of crap that was dumped out half-baked in 10.10 and immediately left to rot. No documentation, examples, user community, or Apple support worth a ****. If you want to automate Mac apps, the only *supported* option that works right is AppleScript. (There's also py3-appscript and SwiftAutomation, which ARE good enough to replace AS, but due to Apple's longtime screwing about I no longer do public support.)


As far as Python is concerned, macOS only ships with Python 2.x, which is grotty and legacy. Only worth using for quick throwaway scripts. For anything else, install the latest Python3 framework from python.org and use pip3 to install the latest PyObjC and whatever other libraries you need—it only takes a couple minutes and saves a lot of hassle down the line.


Swift—meh. As a programming language, it's a bloated monstrosity, riddled with tricky complexities, needless duplication, and artificial restrictions, not to mention second-rate Cocoa support. (Not much different to Python, Ruby, C*, and all the other tiresome C/Algol descendents then. Would kill for a modern Lisp-like with non-sucky syntax.) REPL and Playgrounds are both still a bit naff. Writing simple hashbang scripts in e.g. BBEdit is okay, if a bit slow to startup, but for any complicated code you really need a SourceKit-backed editor to keep you right.


The larger problem is that Apple just aren't very interested in scripting and automation these days, and what they do have is an absolute dog's dinner of failures, has-beens, and never-rans. Now that they've [belatedly] ditched Sal Soghoian, and recently bought Workflow, it's possible we'll see some new plans for scripting and automation at WWDC in June.

Thanks to all for the replies. Yes, you're right that Ruby seems to have been dropped.


I think it's a toss-up between Swift (which is certainly supported by Apple and well documented) and installing the latest python stuff. The advantage of Swift is that is that easily transferred into apps, but by God I hate all that optional crap.


Shell scripting is all very well, but you can't access Cocoa objects and methods, can you?


I guess using any language, you're reliant on somebody supporting it, so to that end it's all temporary. sic transit gloria mundi, and all that.

5. Perl

I do virtually everything in Perl. Perl is installed by default on macOS. If you need to access AppleScript, you could do it via osascript. I've never had Perl fail like Python does on a regular basis. Perl has super-flexible, yet rock-solid syntax. It looks very much like C, but super easy to use.

Which scripting language?
 
 
Q