Posted on 25 March 2008 at 10:58
rb-appscript Example
In my last post, I promised an example of a script that uses rb-appscript instead of AppleScript. Well, remember that screencast that showed how to add events to Timeline? I wrote that script in rb-appscript. Click here for the script.
I chose Ruby for this script instead of AppleScript because Ruby processes text much more efficiently than AppleScript. In this example, I ask the user to choose a data file, then I use a third-party library (FasterCSV) to parse the data file line-by-line. For each line, I add an event to my timeline.
I also chose Ruby because the syntax is much more concise. To process text in AppleScript, you typically have to write several more lines of code than with Ruby or another language. This can lead to considerable time savings while developing a script.I note that this script is not complete. I need to add better error handling and I’d also like to check each line for data consistency. But for demonstration purposes, this script works.
I’d like to hear your comments about moving forward with Ruby or sticking with AppleScript as our scripting language of choice. I’ve heard from a few people and the vote is split. One advantage of sticking with AppleScript is the large amount of existing scripts floating out there for you to examine and learn from. Because rb-appscript is relatively new (but very mature as it’s built on top of Apple Events), the number of existing scripts is small compared to AppleScript. Just another thing to think about before we move forward.
