开发者

AppleScript code to loop messages in Entourage and delete them

I wrote a simpl开发者_如何学JAVAe AppleScript which loops indefinitely inside Entourage Inbox and gets subjects of "unread" messages:

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

Now, the problem is, I want to delete messages after getting the subject. How can I do this? Could you please write me an example?

Thanks again!


Once you delete a message, you have changed the length of the message list, so at some point, you are going to come across an index that no longer exists because you have deleted enough messages. To get around this, you have to (essentially) hard code the loop; get the count of messages, and start from the last message and move up from there. Even though you have deleted a message, the indexes above the current one will always be intact. Untested but is a pattern I've used elsewhere...

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's "convenience" syntax sometimes isn't, and that's why I usually avoid it altogether.


Here is a snippit from an example on Microsoft's Entourage help page (specifically the "Nuke Messages" script):

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜