[英]Using the Apple Scripting bridge with Mail to send an attachment causes the message background to go black
[英]Sending mail attachment with scripting bridge through sandbox
我一直在使用腳本橋來使郵件在10.6和10.7中發送帶附件的郵件,但是表單10.8郵件應用程序本身是沙箱,所以它無法訪問附件文件。
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
從Apple腳本看來,我需要使用附件路徑的別名(在我的情況下是臨時文件),而不是現在使用的路徑,而Mail無法訪問。 有沒有一種簡單的方法來使用腳本brige添加此步驟?
找到解決方案:為了在Mountain Lion中使用沙盒,您必須提供附件的NSURL而不是NSString的文件路徑。
MailAttachment *theAttachment = [[[mail classForScriptingClass:@"attachment"] alloc] initWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:[NSURL fileURLWithPath:eachPath], @"fileName",nil]];
(這也適用於Lion,但在Snow Leopard中你必須使用文件路徑作為NSString)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.