The python syntax and the AppleScript/ObjC syntax are not compatible.
If you are talking about only one argument there is a simple solution with help of NSString's stringWithFormat
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions
to format(theString, tokens)
return (current application's NSString's stringWithFormat_(theString, tokens)) as text
end format
log format("Hello %@", "Apple") -- # Hello Apple
For more arguments you have to use an if - else clause to convert the argument array to the ObjC va_list
to format(theString, tokens)
set numberOfArguments to count tokens
if numberOfArguments = 1 then
return (current application's NSString's stringWithFormat_(theString, item 1 of tokens)) as text
else if numberOfArguments = 2 then
return (current application's NSString's stringWithFormat_(theString, item 1 of tokens, item 2 of tokens)) as text
else if numberOfArguments = 3 then
return (current application's NSString's stringWithFormat_(theString, item 1 of tokens, item 2 of tokens, item 3 of tokens)) as text
else
error "Invalid number of arguments"
end if
end format
log format("Hello I'm %@ and I'm %@ years old", {"John", 25}) -- # Hello I'm John and I'm 25 years old