AppleScript and Writing Scripts
You might have a friend, or even a teenage son, who’s a geek and will work for pizza. In which case it’s possible that you could find them a task or two that would keep them in mozzarella for a while. Alternatively, you may work for one of those companies that’s throwing the PC away and you want to know to what level a Mac can be automated.
Here’s the thing: On a PC there’s VBA (Visual Basic for Applications) which makes it possible to directly automate Microsoft Office applications. So if you want specific things to have when a file is saved, or you want to link word files to spreadsheets directly, then VBA is your language. On the Mac the language is AppleScript and it isn’t confined to just a small set of applications. It works with every app. In fact:
Pretty much anything you can do from the keyboard or the mouse in OS X can be achieved with AppleScript scripts!
You can automate just about anything that you do – but that doesn’t mean you should. Or to be more precise, there’s an intelligent order to how you automate a Mac and you do not begin by scripting. Here’s the way that I look at it:
- Quicksilver coupled with an intelligent use of hot keys will automate many things (see this posting)
- You can further automate by adding more sophisticated hot keys with iKey (see this posting).
- You can go half-way to programming things with AppleScript (because it’s half a programming language)
- If you need to go further then my advice is start using Ruby and write real programs.
If you’re wondering why I’ve not mentioned Automator, the automation program that’s been available with the Mac since the Tiger release of OS X, it’s because Automator is really a wizard capability for assembling scripts. If you’re going to go as far as using Automator, you may as well bite the bullet and write AppleScript scripts. If you really have no idea about programming, Automator may give you an idea of what a scripting language can do – so it can work as a primer. But bear in mind that Automator is quite limited compared to AppleScript.
What is a scripting language?
A script is normally a set of executable instructions that bind together chunks of executable code. A scripting language doesn’t need to be as extensive as a programming language because mostly it’s going to connect a few things together and then add a little bit here and there to create a useful capability. Of course, technically, there is no definitive difference between a scripting language and a programming language. Scripting languages get extended to do things that programming languages do and programming languages, like Ruby for example, can be used to write scripts.