AppleScript gets a bad rap amongst programmers. It’s true, it’s not the most efficient language. It’s miserable at manipulating text. Regex support is non-existent, you have to roll your own sorts and reverses, and it’s got two different file types for compiled and compiled scripts. I’m now on the road to being a Rubyist, and I love Ruby, but AppleScript was the language that got me into programming. The best way to get good at programming is to have a task that you need programming to accomplish. Given a goal, you’ll learn how to make the tool work to perform the task you need it to do. For me, it was scripting OmniFocus, and in order to script OmniFocus, I needed to learn AppleScript. I went through countless online tutorials, bought Hamish Sanderson’s book on AppleScript and then read a lot of Googled and DuckDuckGo’d articles from MacScripter. And while I may have gone about learning AppleScript the hard way (not book first!) I have a pretty good understanding of AppleScript now, and I can often just look at an app’s dictionary and figure out how things should work. (When that fails, email the developer of the app you’re scripting. They often have great example scripts to share.)
I did quickly realize AppleScript’s two big flaws:
- It’s slow.
- It sucks for general purpose work.
AppleScript lacks the low-level speed of a Bash script and it also lacks the nifty iterators that Ruby has. Both writing and running AppleScripts can be slow. If you’re not doing a lot of data manipulation, it’s not that big of a deal, but it’s something to think about.
Probably the bigger problem though is that AppleScript isn’t great with non-application scripting tasks. In order to sort a list in AppleScript, you’ve gotta write your own handler. In Ruby:
a = [1,3,5,10,2,6]
a.sort => [1, 2, 3, 5, 6, 10]
string = "Brandon is a sexy man."
string.reverse=> ".nam yxes a si nodnarB"
I thought all these handy methods in Ruby were awesome, coming from just a background in AppleScript. Bash functions can be extremely hard to write and while I understood how to do them in AppleScript, it’s just a pain to implement.
So, while I do most of my programming in Ruby now (and occasionally Bash), I realize that AppleScript has its uses and that there are certain things (like scripting existing applications) that AppleScript excels at. Don’t be a hater of AppleScript. Best thing we can do is keep using it while at the same time making sure Apple knows people still care about it and want to see it improve.