Obj-C/AppleScript 语法问题

发布于 2024-10-13 19:51:12 字数 955 浏览 5 评论 0原文

我正在从我的应用程序内部调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落花随流水 2024-10-20 19:51:12

您需要使用[NSString stringWithFormat:@"... %@ ...", @"arg"]

You need to use [NSString stringWithFormat:@"... %@ ...", @"arg"].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文