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.
Brock Benjamin on April 2nd, 2008 at 0:42 says:
My vote is for rb-appscript, although i’d guess that once we become familar with it we could easily learn applescript? I love the site. I’ve been looking at applescript and automator for awhile and just can’t find the time to self teach.
Larry Staton Jr. on April 2nd, 2008 at 6:02 says:
@Brock -
Thanks for the kind words. I’ve decided to teach AppleScript syntax because of the amount of existing scripts available and the other resources available for newbies. The rb-appscript community just isn’t that large yet.
However, I will continue to include rb-appscript in the extended version of each post.
Warwick Rothnie on May 18th, 2008 at 22:33 says:
Larry
Your screencast is what finally got me fired up to try and overcome my inertia/intimidation about applescript.
I have many chronologies already existing in filemaker or word, so the ability to simply re-use that data to generate a timeline -wow!
But how does one do it if not a rubyist?
Larry Staton Jr. on May 19th, 2008 at 7:46 says:
@Warwick -
From FileMaker, reusing the data shouldn’t be too difficult. Just grab the data out of FileMaker, then push it into Timeline. I’ll put up an example script during my FileMaker series.
From Word, reusing the data is a bit trickier because you need to parse the text data from Word and, as noted, AppleScript’s text parsing facilities are cumbersome. You would need to take the data out of word, parse it, then push it to Timeline. I’ll have posts on parsing text later in the series.
Text parsing is another advantage of using Ruby over AppleScript.