/>
X
Business

Snow Leopard: Don't get caught in date handling change in AppleScript

As users migrate to Snow Leopard they will find that AppleScript is less forgiving about date and time formatting. Formerly reliable scripts, years old, may fail.
Written by David Morgenstern, Contributor on
snowclose171.jpg
As users migrate to Snow Leopard they will find that AppleScript is less forgiving about date and time formatting. Formerly reliable scripts, years old, may fail. I was reminded of this change in a MacTech article by scripting consultant Ben Waldie, president of Automated Workflows and author of many books on AppleScript scripting.  (The article can be found in hardcopy in the latest issue of MacTech magazine, which is all about Snow Leopard. I bet that many will also appreciate the detailed rundown of changes to launchd in Snow Leopard by Greg Neagle at MacEnterprise.) Waldie says that "coercions from strings to dates are also a bit finicky in Snow Leopard." Previously, AppleScript was more forgiving in its handling of dates, he said. However, now date and times that ran correctly will either fail or work at the wrong time. For example, if you had a script that ran at 5:00 a.m., it won't run. It now needs to be formatted as AM. No periods allowed.

Waldie's example pointed to a date string, 03, September, 2009, that produced an error. It wants to be September 3, 2009. Here's Waldie's suggestion:
To prevent these types of errors, Apple recommends ensuring that any string being coerced to a date match one of the system date formats found in System Preferences, under Language and Text (formerly International)>Formats.
While professional scriptors are more focused on Snow Leopard's significant changes to AppleScript Studio and Script Editor as well as the moving around of preferences and settings, the changes to date handling are serious to your data and workflow. They will catch the casual script writer and user unawares.
Editorial standards