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

Best way to delete all attachments in all messages in specific Mailbox

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

我做错了什么?

谢谢!

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