Macos 通过沙盒发送带有脚本桥的邮件附件
在10.6和10.7中,我一直在使用脚本桥让邮件发送带有附件的邮件,但表单10.8邮件应用程序本身是沙盒,因此无法访问附件文件Macos 通过沙盒发送带有脚本桥的邮件附件,macos,sandbox,email-attachments,Macos,Sandbox,Email Attachments,在10.6和10.7中,我一直在使用脚本桥让邮件发送带有附件的邮件,但表单10.8邮件应用程序本身是沙盒,因此无法访问附件文件 MailApplication *mail = [SBApplication applicationWithBundleIdentifier:@"com.apple.Mail"]; MailOutgoingMessage *mailMessage = [[[mail classForScriptingClass:@"outgoing message"] alloc] i
MailApplication *mail = [SBApplication applicationWithBundleIdentifier:@"com.apple.Mail"];
MailOutgoingMessage *mailMessage = [[[mail classForScriptingClass:@"outgoing message"] alloc] initWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:subject, @"subject",body, @"content", nil]];
[[mail outgoingMessages] addObject:mailMessage];
[mailMessage setVisible:YES];
for (NSString *eachPath in paths) {
if ( [eachPath length] > 0 ) {
MailAttachment *theAttachment = [[[mail classForScriptingClass:@"attachment"] alloc] initWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:eachPath, @"fileName",nil]];
[[mailMessage.content attachments] addObject: theAttachment];
}
}
[mail activate];
我读到一条建议,看看iCal使用AppleScript打开带有附件的邮件的方式:
on send_mail_sbp(subjectLine, messageText, invitationPath)
set pfile to POSIX file invitationPath
set myfile to pfile as alias
tell application "Mail"
set mymail to (make new outgoing message at the beginning of outgoing messages with properties {subject:subjectLine, content:messageText})
tell mymail
tell content
make new attachment with properties {file name:myfile} at after the last word of the the last paragraph
end tell
end tell
set visible of mymail to true
activate
end tell
end send_mail_sbp
从applescript来看,我似乎需要在附件路径(在我的情况下是临时文件)中使用别名,而不是现在使用的无法通过邮件访问的路径。
是否有一种简单的方法可以使用脚本brige添加此步骤?找到了解决方案:要在Mountain Lion中使用沙箱,您必须提供附件的NSURL,而不是作为NSString的文件路径
MailAttachment *theAttachment = [[[mail classForScriptingClass:@"attachment"] alloc] initWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:[NSURL fileURLWithPath:eachPath], @"fileName",nil]];
(这也适用于Lion,但在Snow Leopard中,必须将文件路径用作NSString)