I am trying to save a selected email from Apple Mail using ScriptBridge.
I have already created the Mail.h file and in my program I have successfully done other things with the Apple Mail ScriptBridge (like forwarding messages etc.)
Here is my current code. I get no error messages and the code is running fine; only the file never gets created.
I am using Xcode 4.6. on Mountain Lion 10.8.2. The deployment target of my app is 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);
}
}
}