該腳本一直在使用10.7及更高版本,但在10.8中,似乎已損壞。該行:AppleScript不能在Mountain Lion中工作的路徑
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
在以前的版本上工作得很好,但蘋果顯然阻止它在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
這很可能與授權/沙盒的樂趣有關,但希望有一些解決方法可以與之前的系統具有相同的功能。 – mjdth