【问题标题】:AppleScript code to loop messages in Entourage and delete themAppleScript 代码在 Entourage 中循环消息并删除它们
【发布时间】:2010-09-15 15:17:17
【问题描述】:

我编写了一个简单的 AppleScript,它在 Entourage Inbox 中无限循环并获取“未读”消息的主题:

tell application "Microsoft Entourage"
activate

repeat with eachMsg in messages of folder named "Inbox"
    if read status of eachMsg is untouched then
        set messageSubject to subject of eachMsg as string

        -- bla bla bla

        -- How to delete the message and proceed with the next one???
    end if

end repeat

现在,问题是,我想在获得主题后删除邮件。我怎样才能做到这一点?可以给我写个例子吗?

再次感谢!

【问题讨论】:

    标签: applescript entourage


    【解决方案1】:

    删除邮件后,您更改了邮件列表的长度,因此在某些时候,您会遇到一个不再存在的索引,因为您删除了足够多的邮件。为了解决这个问题,您必须(基本上)对循环进行硬编码;获取消息的数量,并从最后一条消息开始并从那里向上移动。即使您删除了一条消息,当前消息上方的索引也将始终保持不变。未经测试,但这是我在其他地方使用过的模式......

    tell application "Microsoft Entourage"
    activate
    set lastMessage to count messages of folder named "Inbox"
    repeat with eachMsg from lastMessage to 1 by -1
        set theMsg to message eachMsg of folder named "Inbox"
        if read status of theMsg is untouched then
            set messageSubject to subject of theMsg as string
    
            -- bla bla bla
    
            -- How to delete the message and proceed with the next one???
        end if
    
    end repeat
    

    Applescript 的“便利”语法有时并非如此,这就是我通常完全避免使用它的原因。

    【讨论】:

      【解决方案2】:

      这是来自 Microsoft Entourage 帮助页面(特别是“Nuke Messages”脚本)上的示例的片段:

      repeat with theMsg in theMsgs
          delete theMsg -- puts in Deleted Items folder
          delete theMsg -- deletes completely
      end repeat 
      

      【讨论】:

      • 感谢您的回复。是的,我也找到了这个例子,但是如果你在无限循环中运行它,AppleScript 将在删除消息后出错,因为下一条消息的索引将不匹配。你对此有什么想法吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-13
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-05
      相关资源
      最近更新 更多