The task today for Annoture is localization. I’ve been looking far and wide across the Internet for an AppleScript equivalent to Cocoa’s
stringWithFormat method to no avail. The lack of such a native function makes localizing an AppleScript Studio application difficult, as you can’t easily create formatted localized strings such as:
“%d image annotations were copied from %s to %s”
The alternative of creating several strings that I would have to concatenate was not very palatable, so I ended up writing a simple function that uses AppleScript’s
do shell script command to call
on localized_formatted_string(key_string, parameters) set cmd to "printf " & quoted form ofÂ¬ (localized string key_string from table "Localizable") repeat with i from 1 to count parameters set cmd to cmd & space &Â¬ quoted form of ((item i of parameters) as string) end repeat return do shell script cmd end localized_formatted_string
If you’re not doing localization but want printf functionality in AppleScript, take out the line
localized string key_string from table "Localizable" and replace with simply
key_string. Parameters is simply a list of parameters to the printf command.
Now we’ll see how long it takes Google to index this post so people in the future don’t have to struggle as much as I did!