tags:

views:

354

answers:

1

When a script is saved as a bundle, it can use the localized string command to find the appropriate string, e.g. in Contents/Resources/English.lproj/Localizable.strings. If this is a format string, what is the best way to fill in the placeholders? In other words, what is the AppleScript equivalent of +[NSString stringWithFormat:]?

One idea I had was to use do shell script with printf(1). Is there a better way?

A: 

As ugly as it is, calling out to printf(1) is the common solution.

A cleaner, though somewhat more complex, solution is to use AppleScript Studio, which allows you to call into Objective-C objects/classes from your AppleScript code with the call method syntax documented here.

With that, you'd be able to use something like this:

call method "stringWithFormat:" of class "NSString" with parameters {formatString, arguments}

The downside of this, of course, is that you need to write an AppleScript Studio app instead of just writing a simple script. You do get a good bit more flexibility in general with Studio apps, though, so it's not all together a terrible route to go.

nlanza
Unfortunately, there are cases where a script is required rather than an app, and so AppleScript Studio is not an option.
Michael Tsai
AppleScript Studio is now deprecated.
Michael Tsai