首页 > 解决方案 > 删除特定邮箱中所有邮件中所有附件的最佳方法

问题描述

我完全是 AppleScript 新手,我正在尝试编写一个脚本,该脚本将删除指定邮箱 (Mail.app) 中所有邮件中的所有附件。

这是我正在尝试的:

tell application "Mail"
    tell mailbox "Sent" of account id "<XXX>"
        set ListMessage to get every message
        repeat with aMessage in ListMessage
            set aList to get every mail attachment of aMessage
            repeat with aFile in aList
                if (downloaded of aFile) then
                    delete aFile -- this gives an error
                end if
            end repeat -- next file
        end repeat -- next message
    end tell
end tell

运行它会导致错误:

Error: the Apple Event handler failed (errAEEventFailed:-10000)

我究竟做错了什么?

谢谢!

标签: applescript

解决方案


事实证明,这delete不适用于邮件附件,但有另一种解决问题的方法:您可以单击Remove Attachments带有系统事件的菜单项:

tell application "Mail"
    activate
    every item of (get selection)
end tell
tell application "System Events" to click menu item "Remove Attachments" of menu "Message" of menu bar item "Message" of menu bar 1 of process "Mail"

推荐阅读