In an AppleScript Studio application, I’ve been trying to get a “call method “stringWithFormat:” of class “NSString” with parameters” working, but so far to no avail.
Using:
set s to call method "stringWithFormat:" of class "NSString" with parameters "a string"
works and returns “a string”. The following, however, fails:
set s to call method "stringWithFormat:" of class "NSString" with parameters {"a string and %s", "another"}
does not work. It puts up a dialog saying “variable s is not defined” and the log window reports:
*** -[NSMethodSignature getArgumentTypeAtIndex:]: index out of bounds
- I know the right method is being targeted because it works in the first example
- The problem appears to be with the fact that “call method” sees more than one parameter and calls getArgumentTypeAtIndex for each one to determine what the corresponding parameter from the script should be formatted/passed on as. The method is declared with one argument, followed by “…” (meaning variable number of arguments)".
- It appears that the NSMethodSignature class for stringWithFormat: does not encode arguments beyond the first and thus an OOB error results
If the above is correct, it would seem that it is fundamentally impossible to use “call method” with any method that uses a variable number of parameters. Anybody disagree or know better?
If true, does anyone know of a workaround? Adding some additional Objective-C to my project is not an issue, but I’d like something general. I’ve already considered writing a number of “glue” methods with fixed number and type of arguments, but flexibility is reduced this way. (I was thinking of only allowing string type parameters and writing glue for variants with 1-4 %s in the format string.)
Model: Dual G5 (2GHz, 2G)
Browser: Safari 419.3
Operating System: Mac OS X (10.4)