distraction in action
AppleScript is remarkable for being perhaps the worst programming language in modern history that has managed nonetheless to reach a wide audience. This unlikely success can be attributed to the fact that application scripting is fantastically useful and, when it comes to application scripting on the Mac platform, AppleScript has always been pretty much the only game in town.
All that is on the brink of changing, however, thanks to Hamish Sanderson's appscript project. Appscript allows you to do OS X application scripting with Python in a fairly natural, object-oriented fashion. For example, to get a list of the file locations for all photos in the current iPhoto album you can write this Python code:
files = app("iPhoto.app").current_album.photos.image_path.get()
To find out what properties an album has you can write:
So why is this important? To be sure, it has been possible, if awkward, to do app scripting in Python for quite a while now using
Another reason this matters is that OS X is increasingly attracting Linux users who have become tired of recompiling kernels and having flaky hardware support. These people have lots of experience scripting in various languages like Bash and Python. They're not likely to pick up AppleScript since it's such a crappy language and has no application besides OS X app scripting. If they can accomplish the same things in Python, however, then the floodgate opens for all sorts of cool hacks and scripts.
As a demonstration of what I'm talking about, I offer iphoto2album, a script that takes the current iPhoto album and adds it to a photo album made by Album. It requires working installations of iPhoto, appscript, and album, of course. You'll probably need to tweak a couple of parameters at the top of the scripts, but there's nothing too tricky. Granted, this is probably too tricky for the average Mac user, but it's a start.
Speaking of Linux to OS X converts, I was pinged recently by Titus Brown, who was one of the first folks I know to make the jump. He recently established a blog and appears to be updating it frequently, unlike myself. I'm lucky to push out one post a month — he seems to be doing them daily. If his first few posts are anything to go by, the blog should be titled “How to Win Friends and Influence People in the Bioinformatics Software Industry.” BTW, Titus is one of the few people I know who actually writes code as often as he talks about writing code, so he truly has a leg to stand on when he tells you your software sucks ass. Thankfully, my code is generally too short to suck ass. It would have to suck ankle or kneecap or something.