このスクリプトは 10.7 以前では動作していましたが、10.8 では壊れているようです。この線:
set theFilePath to ((path to application support from user domain) as rich text) & "AppFolderName:" & UniqueName as string
set theFileReference to open for access theFilePath with write permission
以前のバージョンでは問題なく動作していましたが、Apple が Mountain Lion での正常な動作を妨げているようです。Mountain Lion で Apple スクリプトを介してそのフォルダにアクセスする他の方法はありますか?
編集:メールルール内で、プログラムがインポートできるテキストファイルにメッセージ全体をエクスポートするスクリプトのコード全体を含めました。テキスト ファイルは ~/Library/Application Support/MyProgram/MailImport/ に送信されます。
私の場合と同じように、ディレクトリがマシンに既に存在していることを確認してください。Appleスクリプトはそれをチェックしません。
path to application support
このスクリプトは、コード内にある場合は機能しませんがpath to desktop
、正常に機能するように変更すると、アプリケーション サポート フォルダーへの書き込みに問題がありますが、コードは機能します。
テストするには、Mail で新しいルールを作成し、Every Message でスクリプトを実行します。~/Library/Application Scripts/com.apple.mail/ にスクリプトを配置する必要があります。
その後、ルール ウィンドウにオプションとして表示されます。メッセージを右クリックして [ルールの適用] を選択すると、個々のメッセージでスクリプトをテストできます。
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with eachMessage in theMessages
set sub to subject of eachMessage
set mid to message id of eachMessage
set sen to sender of eachMessage
set recp to ""
repeat with thisRecpt in recipients of eachMessage
set recp to recp & address of thisRecpt & ","
end repeat
set {year:y, month:m, day:d, hours:hh, minutes:mm} to (date sent of eachMessage)
set dat to (y * 10000 + m * 100 + d) as string
set tim to (hh * 100 + mm) as string
set con to content of eachMessage
set TotalString to "<!STDMessageSubject>" & sub & "<!STDMessageSubject>" & "<!STDMessageID>" & mid & "<!STDMessageID>" & "<!STDMessageSender>" & sen & "<!STDMessageSender>" & "<!STDMessageRecipient>" & recp & "<!STDMessageRecipient>" & "<!STDMessageDate>" & dat & "<!STDMessageDate>" & "<!STDMessageTime>" & tim & "<!STDMessageTime>" & "<!STDMessageContent>" & con & "<!STDMessageContent>"
set UniqueName to do shell script "uuidgen"
set theFilePath to ((path to application support from user domain) as rich text) & "MyApplication:MailImport:" & UniqueName as string
set theFileReference to open for access theFilePath with write permission
write TotalString to theFileReference
close access theFileReference
end repeat
end tell
end perform mail action with messages
end using terms from