Saturday, April 07, 2007

AppleScript: adding a progress indicator to a script

I finally found a need to write (modify) an AppleScript. I'd been kind of hoping Apple would dump AppleScript and switch over to Ruby or (even better) Python as the official AppleEvent scripting language [1]. After some grumbling, though, I was able to get things working. The remaining problems is that execution is dog slow and the progress indicator available from AppleScript is very annoying.

So I was interested in this tutorial ...
AppleScript Studio Tutorial - Getting Started with Displaying Progress

One very common use for AppleScript is batch processing. Scripts of this nature will often loop through multiple items, performing some type of automated task for each item being processed. An example of this might be a script that loops through a folder of image files, converting each one to another format.

A script of this nature that is created with Script Editor, and then run, may work just fine. However, visually, it is less than spectacular. Other than a spinning cursor, and perhaps a dialog message displayed here or there during script execution, the user does not usually receive a very good visual representation of what is occurring.

This is where AppleScript Studio can come in handy. In this month's column, we will discuss adding progress bars and spinners to an AppleScript, in order to provide a visual representation of what is being processed, how much processing is complete, and how much processing remains during script execution.
I'll give it a try, and if I get it running I'll post the code. I've added MacScripter to my feeds as well.

[1] This insightful feeling comment, however, has given me pause:
Posted February 28, 2007 @ 12:57PM by AlanS

... What makes AppleScripting difficult is not the AppleScript language, it is the OSA architecture, which pushes most of the semantics into individual applications. Not only do most applications do an abysmal job of documenting their OSA support, they also differ widely in how they choose implement basic semantics such as object references. Thus, every attempt to use AppleScript often becomes a treasure hunt to find the magic incantation to accomplish a goal. Switching to another scripting language will not solve this fundamental problem...
Which makes me even sadder that "AppleScript for Applications" (out of print) has never been updated. One of the most aggravating things about trying to use AppleScript is that so much is undocumented, under-documented, broken, incompletely implemented ...

No comments: