此脚本一直在 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