我正在使用NSAppleScript從我的OSX應用程序發送電子郵件。 它之前工作正常,但現在當我用新的XCode 9.0與Sierra 10.12.6我有一個問題。應用程序將創建電子郵件並打開包含電子郵件和消息內容的郵件窗口,但不會執行發送。我可以點擊發送按鈕,一切都很好,郵件將發送,但我想避免手動點擊發送按鈕操作。與Sierra一起使用NSAppleScript - 未發生發送操作
我使用的權利:
<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版本(s)運作良好。 我是否缺少權利或什麼?
謝謝!
謝謝你的回覆!將代碼更改爲:send \ n \我有相同的結果。沒有不同。 – rrodic