簡體   English   中英

將附件從郵件保存到外部高清的 Applescript

[英]Applescript to Save Attachments From Mail to External HD

從傳入的郵件消息中,我想將附件復制到外部 HD。 我正在使用腳本通過郵件規則將附件復制到用戶目錄,該規則在看到發件人的電子郵件地址時激活。

我嘗試修改它以復制到外部高清,但據我所知它沒有做任何事情。 這是我修改的內容,我相信attachmentsFolder 是症結所在

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

我很確定“try”塊掩蓋了您無法保存附件的情況。 我現在有同樣的問題,如果您取消注釋“嘗試”和“結束嘗試”行,我敢打賭您會收到有關在 finder 中設置訪問權限的錯誤。 我仍然堅持那個。 盡管設置了完整的磁盤訪問權限,但它似乎沒有獲得寫訪問權限。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM