【发布时间】:2020-07-15 18:30:08
【问题描述】:
感谢大家迄今为止的帮助。很抱歉,我在上一个问题的“答案”部分提出了这个问题,我现在明白我不应该这样做......所以我在这里开始了一个新问题。
所以,我想编写一个脚本,以便在附件到达时将它们保存在电子邮件中 - 每个电子邮件发件人都有一个不同的文件夹。我从这个网站上的人那里得到了很多帮助。
它有点工作......对于新收到的电子邮件它工作得很好,但是当我对我邮箱中的旧电子邮件运行它时,它会保存一些附件而不是其他附件。
我认为问题是查找重复项时出错(我认为这不太可能,因为我已将时间戳与电子邮件的数据戳一起添加到文件名中。)所以我添加了 delFile 删除过程来检查对于同名文件,如果找到则删除它。
当我执行脚本时,它会处理比以前更多的附件,但不是全部......有趣的是,没有任何东西被放入垃圾箱。
我现在被难住了!!作为 AppleScript 的新手,我还不知道如何调试或处理错误。
有人可以帮忙吗?
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 & " " & h & "." & min) as string
set attachmentName to 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
else if originalName contains "ics" then
set doSave to false
end if
if doSave is true then
tell application "System Events"
if not (exists folder (destinationPath & senderName)) then
make new folder at end of alias destinationPath with properties {name:senderName}
end if
end tell
end if
if doSave is true then
set delFile to destinationPath & senderName & ":" & attachmentName
tell application "System Events" to if (exists file delFile) then delete file delFile
end if
if doSave is true then save anAttachment in file (destinationPath & senderName & ":" & attachmentName) with replacing
end repeat
end repeat
end tell
end perform mail action with messages
end using terms from
谢谢
【问题讨论】:
-
在你原来的问题中,我建议你去掉
if...else if并使用 list,甚至给你 code我>为它。我还建议您不要在 date 中使用/,而是使用-。你应该听那些比你更了解的人!