Obj-C/AppleScript 语法问题
我正在从我的应用程序内部调用 AppleScript。我的代码的相关片段如下所示:
-(void)sendMail:(NSString*)addressStr
{
NSString *scriptString = <snip>
@"end tell\n"
@"tell b to make new to recipient with properties {address:\"[email protected]\"}\n"
@"send b\n"
@"end tell\n";
<snip>
}
带有“硬连线”电子邮件地址的脚本运行完美,但我真的想使用我们社区数据库之外的地址。我尝试使用 可变 字符串作为 scriptString,然后在将 scriptString 传递给 AppleScript 对象之前将传递的 addressStr 插入到确切的(已知)索引处。但是,如果我删除(仅)地址字符并尝试类似的操作:
@"tell b to make new to recipient with properties {address:\"\"}\n"
<snip>
[scriptString insertString:addressStr atIndex:556];
...它要么不会编译,要么在运行时给出“尝试使用 insertString:atIndex: 改变不可变对象(??)”错误 - 取决于我尝试什么。
因此,要么我的语法错误(P=0.95),要么我试图用 AppleScript 完成不可能的任务。有人可以帮我吗?预先非常感谢:-)
I'm calling an AppleScript from inside my application. The relevant snippet of my code looks like so:
-(void)sendMail:(NSString*)addressStr
{
NSString *scriptString = <snip>
@"end tell\n"
@"tell b to make new to recipient with properties {address:\"[email protected]\"}\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 :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用
[NSString stringWithFormat:@"... %@ ...", @"arg"]
。You need to use
[NSString stringWithFormat:@"... %@ ...", @"arg"]
.