【问题标题】:Applescript to Save Attachments From Mail to External HDApplescript 将附件从邮件保存到外部高清
【发布时间】: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" 作为路径
  • 我之前的评论对解决问题有帮助吗?
  • 我进行了更改,邮件规则将邮件标记为已读,但脚本不会将附件保存到指定文件夹(或任何地方)

标签: applescript apple-mail


【解决方案1】:

我很确定“尝试”块正在掩盖您无法保存附件。我现在也有同样的问题,如果你取消注释“try”和“end try”行,我敢打赌你会得到一个关于在 finder 中设置访问权限的错误。我仍然坚持那个。尽管设置了完整的磁盘访问权限,但它似乎没有获得写访问权限。

【讨论】:

  • 我也坚持这一点。我试过save this_attachment in file saveDestsave this_attachment in saveDest(= 没有“文件”)导致两个不同的错误,一个说“无法获取附件xyz”之类的名称,它应该保存,尽管有完整的磁盘访问权限,但另一个听起来像是权限问题。有什么进展吗?
猜你喜欢
  • 1970-01-01
  • 2017-05-04
  • 1970-01-01
  • 1970-01-01
  • 2011-12-18
  • 1970-01-01
  • 2012-01-15
  • 2010-11-13
  • 1970-01-01
相关资源
最近更新 更多