【发布时间】:2020-07-14 06:47:17
【问题描述】:
我想将 Mail 中的附件自动保存到我的硬盘中。经过大量研究后,我在 Mail 中设置了一个规则,只要带有附件的电子邮件到达,就会运行下面的脚本。
use scripting additions
using terms from application "Mail"
on perform mail action with messages messageList for rule aRule
set destinationPath to (POSIX file "/volumes/Data/Dropbox/WORK ITEMS/Email Attachments/") as string
tell application "Mail"
repeat with aMessage in messageList
repeat with anAttachment in mail attachments of aMessage
set senderName to (extract name from sender of aMessage)
set {year:y, month:m, day:d, hours:h, minutes:min} to date received of aMessage
set timeStamp to (d & "/" & (m as integer) & "/" & y) as string
set attachmentName to senderName & " - " & timeStamp & " - " & name of anAttachment
set doSave to true
set originalName to name of anAttachment
if originalName contains "jpg" then
set doSave to false
else if originalName contains "jpeg" then
set doSave to false
else if originalName contains "gif" then
set doSave to false
else if originalName contains "png" then
set doSave to false
else if originalName contains "html" then
set doSave to false
end if
if doSave is true then save anAttachment in file (destinationPath & attachmentName)
end repeat
end repeat
end tell
end perform mail action with messages
end using terms from
这很好用。排除停止脚本在电子邮件签名等中保存徽标。 但是这个脚本确实意味着所有文件都在一个目录中(电子邮件附件)。
由于脚本具有发件人的名称,我一直在尝试使用发件人名称在“电子邮件附件”中创建一个子目录(bur 仅在不存在时创建它),然后将文件另存为该目录中附件的“时间戳和名称”。
这样我将在“电子邮件附件”下有一个目录结构,所有发件人姓名及其附件都在他们自己的目录中。
我已经尽我所能 - 但没有成功(我可以在这里发布我最近的尝试,但我宁愿不要脸红!!)
有谁知道如何修改我的脚本来完成这项工作???如果您有任何想法,谢谢...
【问题讨论】:
标签: applescript posix attachment