Quarter Life Crisis

The world according to Sven-S. Porst

« Software fascismMainHaldern Pop 2008 Thursday »

AppleScript vs. perl

220 words

In a way both AppleScript and perl are horrible languages. One of them is unwritable while the other is unreadable. Neither of those tendencies is funny.

An embarrasingly weak point of AppleScript is its handling of text. I doubt that anybody ever wanted to type AppleScript's text item delimiters twice to replace some strings, no matter how cool that apostrophed genitive looks compared to other scripting languages. As soon as you try to do any text processing in AppleScript that is slightly more ‘sophisticated’ than concatenating strings you will find yourself cursing a lot.

Which is why people start saying that you could just cook up a perl script for the string processing, run that from your AppleScript and be happy ever after. It may be an embarrassing way of doing things, but at least it does the job.

Now the big question is of course whether the negative aspects of both languages multiply here and give something positive or whether I should just get off the happy-drugs and acknowledge that we’re dealing with an aesthetic disaster as mixing two different languages in the same file - via a do shell script command or running osascript - can’t possibly be pretty or easily editable.

But assuming that one does this sort of thing anyway, which way would be the best?

August 5, 2008, 1:37

Tagged as applescript, perl.


Comment by wvh: User icon

I’d sooner recommend using Python or Ruby via appscript: http://appscript.sourceforge.net/

August 5, 2008, 3:57

Comment by Martin Michel: User icon

I would definitely opt for the «do shell script» command, but use Python instead of Perl, like shown here:


Or leave the AppleScript syntax behind and start using appscript:


And never forget: AppleScript and women have a lot in common: They are both extremely hard to understand, but can enrich your life tremendously ;-)

August 5, 2008, 8:01

Comment by ssp: User icon

Totally. I think even the scripting bridge stuff they ship with X.5 (no need for extra installs!) should be good for situations like this one.

In our situation we just wanted to retrofit an existing script with some regexp stuff and my friend is quite familiar with perl, so this odd mix seemed like the quickest thing to give results.

If I’m not mistaken, OSA should in principle allow an existing AppleScript to be converted to python / ruby / whatever code, which would be a cool thing to do. Unfortunately I haven’t discovered a tool for doing that yet.

August 5, 2008, 10:17

Comment by ckd: User icon

I’ll second wvh: Python with appscript has been a really nice replacement for AppleScript for my purposes. It’d be nicer if Apple shipped appscript (and for that matter, python-mode for the included Emacs) but it’s not like it’s tough to install.

(I switched to Python after over a decade of writing Perl. I’ve been far more productive in my scripting/toolsmithing ever since.)

August 5, 2008, 22:25

Comment by J Osborne: User icon

I have had luck (like ~3~4 years ago) with Perl’s AppleScript interface Mac::Glue (or was it Mac::GLUE?). I used it to do some non-trivial data gathering and collation between a bug report system that had Apple Script hooks, and a huge pile of psudo-formated ASCII text describing test failures.

It was definitely a lot nicer then attempting to drive perl from an Apple Script.

Since I happened to already know Perl and it was a good fit for the text de-mangleing it was a good choice for me. AppScript looks like a pretty decent thing to try, especially if you want to avoid Perl. For me the real key was using a “real” programming language to send/receive the Apple Events, and not attempting to work directly with Apple Script (with Mac::GLUE it also attempted to sanatise the reply event data, with varying success — most of my “how do I use this” problems came down to getting unexpected types back as replies, in retrospect I would have been better off having to explicictly make a decoder rather then have Mac::Glue guess correctly 75% of the time, and hand me “Objects” in need of decoding the rest of the time (to it’s credit I don’t think it ever mangled something it attempted to decode)).

August 12, 2008, 23:38

Add your comment

« Software fascismMainHaldern Pop 2008 Thursday »

Comments on




This page

Out & About

pinboard Links


Received data seems to be invalid. The wanted file does probably not exist or the guys at last.fm changed something.