我一直在尝试使用AppleScript从Apple Mail下载具有特定主题的附件。由于某些原因,如果我使用手动脚本,则可以从电子邮件中下载附件,但是每当尝试使用规则时,都不会响应。
我尝试使用“来自应用程序“邮件”的术语”和“对邮件执行邮件操作”,但由于某种原因,它无法正常工作。我有一个代码版本,可以从电子邮件中下载附件,但这依赖于我手动运行脚本,并且它仅从我选择的电子邮件中下载附件。
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
set thePath to "Macintosh HD:Users:johnhsu:Attachments"
tell application "Mail"
repeat with theMessage in theMessages
set theAttachments to theMessage's mail attachments
repeat with theAttachment in theAttachments
set originalName to name of theAttachment
set savePath to (thePath & ":" & originalName)
save theAttachment in file savePath
end repeat
end repeat
end tell
end perform mail action with messages
end using terms from
我希望只要主题为“ NetSuite报告”的电子邮件进入我的收件箱,AppleScript就可以运行,但是什么也没有发生。然后,我希望将电子邮件的附件下载到我的附件文件夹中,但是也没有任何反应。什么都没发生。
还请注意,这是我手动运行的代码,它可以正常工作并从我在Apple Mail中手动选择的电子邮件中下载附件。
set thePath to "Macintosh HD:Users:johnhsu:Attachments"
tell application "Mail"
set the selectedMessages to selection
repeat with theMessage in selectedMessages
set theAttachments to theMessage's mail attachments
repeat with theAttachment in theAttachments
set originalName to name of theAttachment
set savePath to (thePath & ":" & originalName)
save theAttachment in file savePath
end repeat
end repeat
end tell