删除特定邮箱中所有邮件中所有附件的最佳方法

时间:2019-11-01 19:26:31

标签: applescript

我是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)

我在做什么错了?

谢谢!

1 个答案:

答案 0 :(得分:0)

事实证明,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"