【发布时间】:2020-04-05 22:15:52
【问题描述】:
从收到的邮件消息中,我想将附件复制到外部 HD。我正在使用脚本通过邮件规则将附件复制到用户目录,该规则在看到发件人的电子邮件地址时激活。
我尝试修改它以复制到外部高清,但据我所知它没有做任何事情。这是我修改的,我相信附件文件夹是症结所在
on perform_mail_action(ruleData)
-- The folder to save the attachments in (must already exist)
set attachmentsFolder to ("Macintosh HD:MegaStore:Sync:logs") as text
-- Save in a sub-folder based on the name of the rule in Mail
set subFolder to name of |Rule| of ruleData as text
tell application "Finder"
if not (exists folder subFolder of folder attachmentsFolder) then
make new folder at attachmentsFolder with properties {name:subFolder}
end if
end tell
-- Get incoming messages that match the rule
tell application "Mail"
set selectedMessages to |SelectedMessages| of ruleData
repeat with theMessage in selectedMessages
-- Get the date the message was sent
set {year:y, month:m, day:d, hours:h, minutes:min} to theMessage's date sent
set timeStamp to ("" & y & "-" & my pad(m as integer) & "-" & my pad(d) & "-" & my pad(h) & "-" & my pad(min))
-- Save the attachment
repeat with theAttachment in theMessage's mail attachments
set originalName to name of theAttachment
set savePath to attachmentsFolder & ":" & subFolder & ":" & timeStamp & " " & originalName
try
save theAttachment in savePath
end try
end repeat
end repeat
end tell
end perform_mail_action
-- Adds leading zeros to date components
on pad(n)
return text -2 thru -1 of ("00" & n)
end pad
【问题讨论】:
-
您对现在不起作用的工作脚本做了哪些更改?您应该始终明确而具体地展示什么是有效的,什么是无效的。也就是说,
set attachmentsFolder to ("Macintosh HD:MegaStore:Sync:logs") as text也不指向用户文件夹或任何外部位置。看看:How to create a Minimal, Reproducible Example -
我只更改了这一行:'''set attachmentsFolder to ("Macintosh HD:MegaStore:Sync:logs") as text 它使用这一行:将附件文件夹设置为((主文件夹的路径为text) & "Sync:logs") as text 否则从上到下是同一个脚本
-
这个 path
"Macintosh HD:MegaStore:Sync:logs"指向内部磁盘,而不是外部磁盘。如果挂载磁盘的名称是MegaStore,则使用"MegaStore:Sync:logs"作为路径。 -
我之前的评论对解决问题有帮助吗?
-
我进行了更改,邮件规则将邮件标记为已读,但脚本不会将附件保存到指定文件夹(或任何地方)