A Runaway AppleScript Nightmare
Live and learn, as they say…
I was in the midst of writing an AppleScript to query the package contents of an application and extract its icon when this happened. I set up an unconditional repeat in my script to open every .icns file for a selected application in its own Preview window - this was a big mistake. Some applications, like Mail.app, for instance, have only a few icon files, so opening every one isn’t a big deal. But when an application supports tons of file types, it tends to have a separate icon for each one. This is the case with Pixelmator (YUV? XBM?). Click on the pictures below to enlarge them.
As you can see, I got myself into a big mess - more than a hundred preview windows opening at rapid speed and suffocating my CPU! Unfortunately, as the fireworks showed no signs of stopping, I had to force quit Script Editor (which is where I ran the script from, thankfully) and I lost some of my unsaved work.
The lesson here, I think, is that while it’s great and necessary to experiment with methods, care must be taken to guard against the ghosts in the code. I am an amateur with AppleScript but I have a lot of fun with it. Nevertheless, it’s a powerful tool and should be respected as such.
In any case, I’ve finished the script and am writing it up for you right now! It’s a good one, I think - and it’s secure. I’ll update this entry with a link to the script once I post it.


