Things.app, AppleScript and Ruby
Let me make a controversial statement: Apple should get rid of AppleScript and just replace it with Ruby (or Python, maybe - if it was Python, I’d be perfectly happy, although I’d prefer Ruby). Really, there is no contest. AppleScript is an atrocious mess of a language. But it’s also bloody slow.
Here is my example. I use a task management app on Mac called Things.app. It’s one of those Getting Things Done-inspired app. It’s pretty nice, and it syncs well with the iPod touch. They have an AppleScript API, and so a lot of people have started building little AppleScripts that do stuff with it. I started using Today Reminder. I downloaded it, and had to hack around a bit with it to get it to work. But here was the main problem: it’s slow and intrusive. I set it to run every half an hour. Every half hour, an application would spawn up, grab focus away from whatever I was doing, replace my menu bar with it’s own and then do whatever it needs to do. I mean, all it does is pop up some Growl notifications. Why does it need to do that and spawn it’s own application chrome? It also had a problem with crashing.
It’s been bugging me for weeks. I’ve told myself that I’m going to sort it out. I finally have, and here are the results - things_growl_today.rb. As a point of comparison, here is the original AppleScript version. It’s a perfect case study in the unadulterated shitness of AppleScript. The Ruby version is less than half the length and a hell of a lot more readable. Okay, the Ruby version does something slightly different from what the AppleScript version does - but the Ruby version does precisely what I want, so that doesn’t matter. I’ll probably hack it a bit later to use proper process objects (.NET kids got this right: System.Diagnostics.Process - if you are Apple or Sun or anyone else maintaining a programming platform, steal this fucking thing and implement the same API. If you are using an OO language, ps hacking ought to be a thing of the past.)
A lot of people seem to think that because AppleScript is written in pseudo-English, it’s easier to understand. I don’t buy this. But I may just be used to reading Ruby and have developed some particular neurosis about AppleScript. Are my intuitions right? The Ruby version is a lot nicer, right? Is there anyone out there who really understands the AppleScript version but doesn’t understand the Ruby version? The only thing that seems particularly complex about the Ruby version is the regex on line 4. You’d have to know about ps, I guess. But in AppleScript land, you have to know about System Events and the dictionary around application processes and so on.
If my intuitions about AppleScript are correct, is there any good reason why AppleScript is not dead? The language is shit. The editor sucks (seriously: you can’t save if the code doesn’t compile? What kind of retardation is that?). The runtimes it creates are slow. Why don’t Apple just kill it? There are plenty of awesome languages you could use instead: Ruby, Python, Lua. Whatever. Just get on with it and stop moaning. I firmly believe in the idea of AppleScript: users should be able to easily hack their applications and desktop environment together in a better way than the designers of Windows/Mac OS/GNOME etc. originally planned. The best way for Apple to pursue the AppleScript dream is to kill AppleScript and build something good.
And, yes, I know I’m wrong. You don’t have to remind me.