In case you happen to have missed it, an Apple announcement has claimed the number one spot on Hacker News this morning. As tired as we all are of Apple and the endless speculating and PR barrage, this one is different from most all of the others.
For those that aren’t familiar, the OS X operating system has long supported the ability to script and automate tasks using something called AppleScript. Why would you want to do this? Because it allows the user to automate repetitive tasks that otherwise require user interaction.
As a simple example, assume that you frequently email files to the same group of people. You may click to compose a new email, click the “attach” icon, browse for the document, select it and then click send. You could write an AppleScript to automate that task so all you have to do is right-click on the file you want to send, and select “send to group”. Virtually any interaction you can have with OS X can be automated, which means you can get really advanced. One user has a script which reads his calendar for hours he’s billed, creates an invoice in Excel and sends that invoice to the client.
Historically, these tasks were composed with AppleScript (or Automator), which is a proprietary scripting language from Apple that aimed to simplify the scripting process through the use of natural language.
For instance, if you wanted to show a simple “Hello World” dialog, you could write the following AppleScript
tell application "Finder" display dialog "Hello World" end tell
Not only does Apple provide an API for interacting with the operating system and install apps, but they also provide an Objective-C bridge to work directly with native libraries such as Cocoa. This is HUGE. Just look at what Apple themselves have to say about it…
We’ve just moved one step closer to that elusive unicorn – write once, run anywhere.
Several folks have written and provided more information about HOW this actually works and how you can do it yourself…