Having worked in the IT profession for more years than I care to mention and completed a bit of formal academic training in Computer Science, I've learned my share of computer languages. In all of my time in this business, I have come across anything as backward, counter-intuitive, or as poorly documented as AppleScript. This should have taken no more than a few minutes and a couple lines of code. Instead, it took me the better part of an evening, too many lines of code, and a google scavenge hunt that yielded less than I could accomplish by trial and error. Who would have guessed that the line
set m to month of (current date)would return a value that looks like a string (e.g., December) but is actually the name of a class that apparently does nothing useful and offers no obvious way of dealing with it directly? The only solution I could come up with was a large "if-then" statement. Overly verbose code grates on my nerves like fingernails on a chalkboard. The script worked, but I was not happy with the solution.
I spent the rest of the evening nursing a beer and mulling over the idea that there had to be a better way to do this. After giving it some thought, I realized that I've been missing the point about AppleScript. AppleScript is a glue language like shell scripting or something like TCL/TK. You can do complex and sophisticated things with shell scripting, however the best way to use the shell is to manage input to smaller programs that do one thing and one thing well. AppleScript is similar in spirit. AppleScript has the ability to do complex and sophisticated things, however the best way to use it is to manage a task through a pipeline of applications that excel at a given task. AppleScript brings a sort of gestalt to the Macintosh. Gluing applications together to take advantage of their unique capabilities makes them more valuable together than they are individually. This is the Zen of AppleScript.
I mentioned that the code example that appears in the Audio HiJack Pro documentation is just an AppleScript that wraps a simple bash shell script. I started this exercise thinking that jumping out to the shell was a kludge. Instead, this is the one of the more elegant solutions to the problem. Next time I'm faced with a problem that requires the use of AppleScript, I won't forget this lesson.
That doesn't forgive Apple for creating a language that feels like some sort of bastard child of American English and Emacs LISP.