Skip navigation.

Harold's Home

   Home
  
XML version of this site

PHP Scripts

Index
CLI fun
Mail on 404
HB-NS (NewsScript)

Downloads

Applescripts
APOD to Desktop
Dreamweaver Extensions

Stuff

Writings
Other stuff
Central Grinder

OOOk Default:

VJ stuff
VJ Tools
Bananas
Strippers
Sample Movies

News

set newbie to yes
After much soul-searching and procrastinating I've decided that the next language I'll learn is Applescript. They say you should learn a new computer language every year. This is bullshit of course. You should never, ever, listen to THEM.

I thought about Python for a while but it's significant whitespace is frightening me.
I also thought about finally really digging into Perl as I got a book on that last year and never got further than chapter three. I'm still recycling the same old code I've been recycling for years and it's serving me pretty well so far.
The fact is that I'm now old enough to realise that I'll never be a real programmer. I'm a webmaster and knowing something about the big scripting languages is extremely useful but I won't be writing the next big CMS, nor do I want to.

As regular readers will have noticed I've been enamoured with Applescript for a while now and after struggling with some of the syntax this weekend I decided it was time for a more formal education.
So I've gotten me O'Reilly's AppleScript: The Definitive Guide because it's up-to-date and got good reviews on Amazon. I also read the sample chapter on the O'Reilly site and it looks thorough.

Besides, the beauty of Applescript is that is has grown immensely in the past few years. For instance the ability to integrate various commandline tools and scripts written in interpreted languages like Perl or Python is a big bonus.

Case in point. Here's the script I wrote this weekend:
-- check to see if the disk image is already mounted
if (list disks) does not contain "The Frozen Throne" then
  do shell script "hdiutil mount -quiet -noverify \"/Volumes/Riktor/Rescued Stuff/The Frozen Throne.dmg\""
end if

-- start The Frozen Throne
tell application "The Frozen Throne"
  activate
end tell


The script is an automated process of something I do quite frequently.
Whenever I play Warcraft I dislike locating and putting in the CD-ROM. Therefore I have created a diskimage that I mount on the desktop (Warcraft refuses to run without the CD). After the diskimage is mounted I start Warcraft to begin playing.

This script first checks whether the volume "The Frozen Throne" is already mounted or not. If it isn't then we mount the diskimage using the commandline tool hdiutil, which is faster than the Finder doing so as we can suppress all feedback and skip the verification process (it is known to be good). After that the script starts Warcraft.
Saved as an application this script is about thirty times faster than manually doing all the steps above.

Now here's the biggie. While the script above is pretty readable (although it is obfuscated a bit by the commandline tool language), Applescripts biggest failing is that the syntax is just too much like english and not enough like traditional programming languages. To assign a value to a variable you don't use $var = "value"; but you use set var to "value". It has numerous other oddities as well like in searching and replacing strings etc.
Anyway, Applescript has been called the most readable of all computer languages but the hardest to write. These claims are questionable if not downright false but they do contain a nugget of truth. Who could imagine that the syntax for getting the list of mounted volumes is (list disks)? Not me, that's for sure.

Anyway, expect more half-baked Applescripts in the near future as I automate my life. (Or watch me ditch Applescript at yet another language man was not meant to learn. Who knows, anything can happen!)

Show all items | Read all items

About, copyright, privacy and accessibility | Mail