我正在尝试使用 ScriptBridge 从 Apple Mail 中保存选定的电子邮件。
我已经创建了 Mail.h 文件,并且在我的程序中,我已经成功地使用 Apple Mail ScriptBridge 完成了其他事情(比如转发消息等)
这是我当前的代码。我没有收到错误消息并且代码运行良好;只有文件永远不会被创建。
我正在使用 Xcode 4.6。在山狮 10.8.2 上。我的应用程序的部署目标是 10.8。
- (void)saveEmail {
MailApplication *mailApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.Mail"];
SBElementArray *viewers = [mailApp messageViewers];
for (MailMessageViewer *viewer in viewers) {
NSArray *selectedMessages = [viewer selectedMessages];
@try {
for (MailMessage *selectedMessage in selectedMessages) {
NSString *filePath = [NSString stringWithFormat:@"%@%@",@"/Users/patrick/Documents/",@"tmp.rtf"];
NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
[selectedMessage saveIn:fileUrl as:MailSaveableFileFormatNativeFormat];
}
}
@catch (NSException *exception) {
NSLog(@"Exception:%@", exception);
}
}
}