Dear MacScripters,
Okay, so call me greedy, but I decided to try to write a single AppleScript handler that would be able to localize strings, then run printf. If the Satimage osax was installed, it would use that printf extension, otherwise it would create a UNIX command and do that. So I naively used a try-block and used the UNIX as the fall-back. However, I realized that this couldn’t possibly work. If the Satimage osax wasn’t installed - then there would be a compile-time, not run-time error.
Gulp, that’s the trouble.
Because, even with this obvious impossibility - it works!?!? Here is my code as it appears on my Mac which has Satimage osax installed:
set convertedString to "Outside temperature has exceeded the threshold of: %dËš at %s."
set variableList to {50, "2:19pm"}
localizeVarStrings(convertedString, variableList)
on localizeVarStrings(localString, variableList)
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- Routine to localize a string that includes printf formatting codes and then
-- substitute the values for the format codes.
-- uses Satimage osax when installed and UNIX printf command
-- as fall-back
--
-- Thanks to Adam Bell for nifty list to string concatenation.
-- http://macscripter.net/viewtopic.php?pid=53342#p53342
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
local convertedString, variableString, tdl, quotedVariableList, variableValueStr
-- First get translated string from localizable.strings file
set convertedString to (localized string localString)
try
-- try Satimage printf extension
set convertedString to printf convertedString parameters variableList
on error
-- Convert values for printf into shell-friendly form.
set quotedVariableList to {}
repeat with variableValue in variableList
set variableValueStr to contents of variableValue as string
set end of quotedVariableList to quoted form of variableValueStr
end repeat
-- Now make printf values into a single string
set {tdl, text item delimiters} to {text item delimiters, space}
set variableString to quotedVariableList as string
set text item delimiters to tdl
set convertedString to quoted form of convertedString
-- Finally let UNIX do the printf work.
set convertedString to do shell script ("printf " & convertedString & space & variableString)
end try
return (convertedString)
end localizeVarStrings
If I copy this script to a Mac that doesn’t have Satimage osax installed, the line:
set convertedString to printf convertedString parameters variableList
looks instead like this:
set convertedString to «event SATIprtf» convertedString «class para» variableList
However, that doesn’t generate a compile-time error. Now I recognize that these are raw Apple events and my understanding is that this should be reasonable. The «event SATIprtf» is unavailable on Macs without the Satimage osax installed, so the handler goes on to do the error code which uses the UNIX printf just as I want to.
However, . . . . this sure look a little weird to me. Am I doing something crazy here that only a AppleScript guru would properly understand? Can code like this be distributed without risking problems for “innocent users”?
Curious minds want to know!! 
Cheers, Edouard 
P.S. Here is a link to printf localized string test.scptd file complete with the localized string resources for folks to play with. According to the tests I’ve run, this file should work on any Mac, even if just cutting and pasting the code above will not work unless you have the Satimage osax installed.