Summary:

I talk to Adam about his latest book, the role of AppleScript in Mac OS X and how he came up with the example scripts used in the book.

AppleScript Missing Manual ImageEverybody has heard of AppleScript, but unfortunately it doesn’t seem to get as good press as other tools in the OS X space. This is odd as it’s one of the most useful and prolific parts of the operating system and applications. AppleScript is like the macros of other applications, except that it’s everywhere. There are few mainstream applications which can’t be controlled with AppleScript, including PhotoShop, Microsoft Word and iTunes. Unlike a macro though, AppleScript is a system service; you run an AppleScript and it tells the application what to do .

AppleScript can also be used to control the operating system too; copy files, move them, reorder and rename them. It’s all possible with AppleScript. Because AppleScript controls these elements from the outside we can combine them. Want to download some music, import it into iTunes, convert it to MP3 and then copy it over to your network share? Use AppleScript!

Maybe what’s missing is the documentation? Well here to help is Adam Goldstein, author of AppleScript: The Missing Manual. I talk to Adam about his book, the scripts he created and his software company, GoldfishSoft.

AppleScript seems to be a forgotten technology to many since the release of OS X. Would you agree with that?

Not at all! For the first few years Mac OS X was out, Apple put AppleScript on the back burner to focus on more important stuff – like stability and security. But now that Mac OS X has had a chance to mature, Apple’s been updating AppleScript left and right with new features and technologies. Things like GUI Scripting (for controlling any program with AppleScript) and AppleScript Studio (for developing full-fledged professional programs) have been made possible only because of Mac OS X – and tons of users are getting hooked on these powerful, free AppleScript tools.

Could you tell us a bit about how AppleScript works and where it fits into the facilities provided by OS X?

Sure: AppleScript is a computer language built around the Open Scripting Architecture, a powerful standard for inter-application communication.
In non-Ph.D. terms, though, AppleScript is an English-like language that lets you control virtually any program on your Mac. In AppleScript, you send individual commands to individual programs – asking Photoshop to crop an image, for example. One benefit of doing such jobs with AppleScript, though, is that you can repeat them over and over again – cropping a whole series of images automatically, for example, rather than cropping them one at a time.
But AppleScript controls non-graphics programs as well: iTunes, Safari, FileMaker Pro, and many more. You can automate complicated tasks within one program, between multiple programs, and you can even automate Mac OS X itself.

What struck me first about the book was the amazing range of things you could do with AppleScript. How do applications dictionaries fit into this functionality?

Application dictionaries are the equivalent of a bad boss – they tell you what you should do, but don’t help you do it. If you want to find out how to access Microsoft Word’s thesaurus, for example, you have to look in Microsoft Word’s dictionary, find the proper command, and then write an AppleScript that incorporates the command. But Word’s dictionary doesn’t give you examples on how to use the command, so you’re stuck either trying to figure it out on your own, or reading a book that shows you how :)

AppleScript is defined as ‘English like’, how far exactly does the ‘English’ part of that definition go?

As computer languages go, AppleScript is the most English-like you can get. On the other hand, you can’t just type English words like “clean up my hard drive at 10:45 tonight” and expect AppleScript to understand them. In reality, AppleScript is somewhere in between; you can understand what most scripts do just by reading them, but the language does have a specific grammar you have to follow.

Do you find it odd that Apple don’t push AppleScript heavily, considering it’s usefulness? Some of the tools seem hard to find, for example.

It’s very odd. AppleScript is way more useful than some features that Apple advertises heavily (the Dock minimizing effect, among others), and AppleScript is completely free! All I can guess is that Apple doesn’t advertise AppleScript much because they’re afraid of seeming too programmery, and they’re trying to appeal more to beginner users. But even there, Apple’s PR department is mistaken, since beginners can use tons of AppleScript tricks (like getting the current weather map or launching programs from the menubar) without writing a single line of code.

There are some pretty cool scripts in here; I particularly like the Photoshop and iPhoto ones. Anything that you would have liked to include but couldn’t?

Not really. I felt good that I could cover the big-name Mac apps (Address Book, FileMaker Pro, Photoshop, and so on), and show how you can use them in conjunction.

Do you see AppleScript as a better solution for some tasks compared to, say, shell scripting the functionality, or using Perl or Ruby?

Absolutely. For certain tasks – like automating common Mac programs – AppleScript is the easiest and most powerful language around. Doing that sort of job with Perl or Ruby would be like trying to inflate your car’s tires with a coffee maker.
On the other hand, I’d never recommend using AppleScript as a standalone scientific data-analysis tool, for example. And if all you ever want to do is automate Unix commands, shell scripting would certainly be more efficient than AppleScript.
Of course, there’s no reason you have to use just one language. AppleScript can run Perl commands, for example, and Perl can run AppleScript commands, so you can use different languages for simplifying different parts of a complex job.

My favourite script has to be the AirPort signal strength tool. How do you come up with the ideas for the scripts?

I just created scripts that I thought people would find useful. For example, I used to walk around my house searching for the best AirPort signal strength, since the walls in my house tend to interfere with the signal. But then I figured, “Why not write a script that alerts me when I’ve found the strongest signal?” In about 5 minutes, I had it cooked up, and I incorporated it right into the book.
The same goes for the other scripts, too. In iTunes, for example, I always wondered why you couldn’t convert a music file to a different format without the file staying in your Library window. Writing a script to work around that annoyance was another no-brainer.
Really, the idea is just to use AppleScript as a tool to get past the quirks and limitations of Mac OS X.

Folder actions seem like an obvious solution to a common problem. Could you tell us more about how these work?

Definitely. Folder actions are AppleScripts that run whenever you do something to a folder. You get to specify the trigger (like dragging files the folder) and the script that should run when the trigger’s set off. From then on, whenever someone (either you or someone on your network) triggers the action, your script will run automatically.
Folder action scripts are very powerful – and even more powerful when you consider that you can write your own. As I show in the book, for example, you can create an action that forwards any files dragged into a folder straight to the Trash. Then, if you move this Trash-forwarding folder to your Finder toolbar, you can delete files simply by dragging the files onto the toolbar – a trick that would otherwise require lots of annoying Unix commands.

Many will undoubtedly be surprised that you are still at high school. How did you become such an AppleScript fan?

I used to be a big fan of HyperCard, a scripting tool back when Macs were still black and white. I remember fooling around with AppleScript pretty early on, and being pretty impressed with its ability to control other programs. But for a while, I left AppleScript to the side, and spent most of my time working on more important things – like getting through middle school.
Once Mac OS X came out, I decided to get back to AppleScript. I spent a lot of time playing around with dictionaries, and when AppleScript Studio came out, I pounced on it. AppleScript Studio got me seriously into writing Mac OS X programs; it’s really an awesome tool for beginners.
Learning all this stuff on my own, though, was a real pain, so I decided to write a beginner-friendly book. In the process of writing the book, I discovered all sorts of unusual and interesting uses for AppleScript – and that’s what really made me such a big fan.

How did you fit writing the book around all your other projects?

I outsource my homework to India.

Can we expect any new applications from GoldfishSoft?

Yes! In the next few months, you can expect an upgrade to SaveMe (our new utility for adding auto-save to any Mac OS X program), as well as a few other surprises. Keep your browser loaded to www.goldfishsoft.com for the latest.

Have you thought about taking up this book and software writing full time (once you’ve finished your studies, of course!)?

I’ve certainly thought about it. At this point, though, I’m thinking more about where I want to go to college.

Do you have a favourite daily comic?

Jon Stewart is my favorite Daily comic.

What can we expect next from the keyboard of Adam Goldstein?

78 keys and a numeric keypad :)

Adam GoldStein Bio

Adam Goldstein got his programming start in Kindergarten, when he first played around with Logo on an old Apple II. Through middle school, Adam wrote useless but amusing HyperCard programs. Nowadays, he runs GoldfishSoft, a shareware company that makes games and utilities for Mac OS X. Adam was a technical editor for O’Reilly’s best-selling Mac OS X: The Missing Manual, and an editor for Mac OS X Panther Power User. When he’s not writing books or code, Adam attends high school in New Jersey, where he is captain of the Debate and Quizbowl teams and an editor of the school paper.

Comments have been disabled for this post