我正在使用 NSAppleScript 从我的 OSX 应用程序发送电子邮件。它以前运行良好,但现在当我将新的 XCode 9.0 与 Sierra 10.12.6 一起使用时,我遇到了一个问题。应用程序将创建电子邮件并打开包含电子邮件和消息内容的邮件窗口,但它不会执行发送。我可以点击发送按钮,一切都很好,邮件会发送,但我想避免手动点击发送按钮操作。
我正在使用权利:
<plist version="1.0">
<dict>
<key>com.apple.security.scripting-targets</key>
<dict>
<key>com.apple.mail</key>
<array>
<string>com.apple.mail.compose</string>
</array>
</dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
这是代码:
NSString *emailString = [NSString stringWithFormat:@"\
tell application \"Mail\"\n\
set newMessage to make new outgoing message with properties {subject:\"%@\", content:\"%@\" & return} \n\
tell newMessage\n\
set visible to false\n\
set sender to \"%@\"\n\
make new to recipient at end of to recipients with properties {name:\"%@\", address:\"%@\"}\n\
tell content\n\
",subjectt, bodyText, @"Company", toAddress, toAddress];
emailString = [emailString stringByAppendingFormat:@"\
end tell\n\
set visible to false\n\
send newMessage\n\
end tell\n\
end tell"];
NSLog(@"%@",emailString);
NSAppleScript *emailScript = [[NSAppleScript alloc] initWithSource:emailString];
[emailScript executeAndReturnError:nil];
所以一切就绪,但发送操作失败。再次,它与旧的 OSX 版本运行良好。我是否缺少权利或什么?
谢谢!