首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在环境中循环和删除消息的AppleScript代码

在环境中循环和删除消息的AppleScript代码
EN

Stack Overflow用户
提问于 2010-09-15 23:17:18
回答 2查看 460关注 0票数 0

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

代码语言:javascript
复制
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

现在,问题是,我想在获得主题后删除邮件。我该怎么做呢?你能给我写个例子吗?

再次感谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-09-16 22:52:58

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

代码语言:javascript
复制
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的“方便”语法有时并非如此,这就是我通常完全避免使用它的原因。

票数 0
EN

Stack Overflow用户

发布于 2010-09-15 23:32:47

以下是Microsoft的Entourage帮助页面上的一个示例(特别是"Nuke Messages“脚本)中的一段代码:

代码语言:javascript
复制
repeat with theMsg in theMsgs
    delete theMsg -- puts in Deleted Items folder
    delete theMsg -- deletes completely
end repeat 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3719085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档