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

アップルスクリプトから、メールで到達できない現在使用されているパスではなく、添付ファイルパス(私の場合は一時ファイル)のエイリアスを使用する必要があるようです。スクリプトbrigeを使用してこのステップを追加する簡単な方法はありますか?

4

1 に答える 1

3

解決策を見つけました。Mountain Lion でサンドボックス化を使用するには、ファイル パスの代わりに添付ファイルの NSURL を NSString として指定する必要があります。

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

(これは Lion でも機能しますが、Snow Leopard ではファイル パスを NSString として使用する必要があります)

于 2012-06-26T05:02:34.910 に答える