Obj-C/AppleScript syntax problem
I'm calling an AppleScript from inside my application. The relevant snippet of my code looks like so:
-(void)sendMail:(NSString*)addressStr
{
NSS开发者_运维百科tring *scriptString = <snip>
@"end tell\n"
@"tell b to make new to recipient with properties {address:\"someone@somewhere.com\"}\n"
@"send b\n"
@"end tell\n";
<snip>
}
The script with "hard-wired" email address runs perfectly, but I really want to use addresses out of our community database. I tried using a mutable string for the scriptString, then inserting the passed addressStr into it at an exact (known) index before passing scriptString to the AppleScript object. But if I remove (only) the address chars and try something like:
@"tell b to make new to recipient with properties {address:\"\"}\n"
<snip>
[scriptString insertString:addressStr atIndex:556];
...it either won't compile or gives an "Attempt to mutate immutable object (??) with insertString:atIndex:" error at runtime -- depending on what I try.
So either my syntax is wrong (P=0.95), or I'm trying to do the impossible with AppleScript. Can anyone help me out, please? Thanks a lot in advance :-)
You need to use [NSString stringWithFormat:@"... %@ ...", @"arg"]
.
精彩评论