【问题标题】:how to delete a mail mailbox with Applescript如何使用 Applescript 删除邮件邮箱
【发布时间】:2015-10-20 02:03:24
【问题描述】:

我希望我的脚本遍历邮箱树并删除空邮箱:

tell application "Mail"
    my cleanup(mailbox "Archives")
end tell

on cleanup(box)
    tell application "Mail"

    if (count of mailboxes of box) > 0 then
        repeat with mbx in mailboxes of box

            my cleanup(mbx)
        end repeat
    else
        if (count of messages of box) = 0 then delete box
    end if


    end tell
end cleanup

“删除框”导致错误: 错误“邮件出现错误:无法获取邮箱“存档”的每个邮箱的项目 1 的每个邮箱的项目 1。”邮箱“档案”的每个邮箱的项目 1 的每个邮箱的项目 1 的编号 -1728

【问题讨论】:

    标签: email applescript


    【解决方案1】:

    有两个问题:

    • 行中的索引变量mbx

    repeat with mbx in mailboxes of box
    

    是类似item 1 of every mailbox of box 而不是mailbox "something" of box 的引用。您必须在使用 contents of 将变量传递给处理程序之前取消对变量的引用。

    • 在同一行中,例如,如果第 1 项已被删除,第 2 项现在是第 1 项,并且不再有第 2 项,您将收到错误消息。为避免这种情况,请使用关键字 get 检索不受循环期间删除影响的复制引用。

    tell application "Mail"
        my cleanup(mailbox "Archives")
    end tell
    
    on cleanup(box)
        tell application "Mail"
    
            if (count of mailboxes of box) > 0 then
                repeat with mbx in (get mailboxes of box)
    
                    my cleanup(contents of mbx)
                end repeat
            else
                if (count of messages of box) = 0 then delete box
            end if
    
        end tell
    end cleanup
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-27
      • 2016-03-09
      • 2012-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-07
      • 2016-09-12
      相关资源
      最近更新 更多