2012-06-21 105 views
1

我一直在使用脚本桥使邮件发送附件为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 

从AppleScript的好像我需要使用的别名附件路径(在我的情况下是一个临时文件),而不是现在使用的邮件无法访问的路径。 有没有简单的方法来使用脚本brige添加此步骤?

回答

3

找到了解决方案:为了在Mountain Lion中使用沙盒,您必须提供附件的NSURL而不是NSString的文件路径。

MailAttachment *theAttachment = [[[mail classForScriptingClass:@"attachment"] alloc] initWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:[NSURL fileURLWithPath:eachPath], @"fileName",nil]]; 

(这也适用于狮子,但在雪豹,你必须使用作为NSString的文件路径)