Title: Re: How to Applescript deletion of multiple items?
On 9/4/01 8:48 PM, "Jeff Porten" <[EMAIL PROTECTED]> wrote:

Problem: when I’m offline I flag messages that I want to come back to when I’m back on the Net (to look up URLs and the such).  So I’d like to have a command that deletes all of the messages in a folder EXCEPT the ones I have flagged.

For a while I just tried sorting and deleting the rest, but that was just annoying.

Applescript to the rescue: I wrote the following script, which works just fine.  But it’s darned slow.

tell application "Microsoft Entourage"
    set StartTime to the current date
    set currMsg to the current messages as list
    set MsgCount to count of currMsg
    set NoFlagMsg to {} as list
    say (MsgCount as text) & " items to check"
    repeat with eachMsg in currMsg
        if flagged of eachMsg is false then
           copy eachMsg to the end of NoFlagMsg
        end if
   end repeat
   repeat with eachItem in NoFlagMsg
        delete eachItem
        set MsgCount to MsgCount - 1
        if (MsgCount mod 25 = 0) and (MsgCount > 0) then
           say (MsgCount as text) & " to go."
        end if
   end repeat
   set ElapsedTime to (current date) - StartTime
    say "Elapsed time: " & ((ElapsedTime div 60) as text) & "  minutes " & ((ElapsedTime mod 60) as text) & " seconds."
end tell

The main problem is in that delete loop: it deletes the messages one at a time, and on my system (500 mHz G4) takes about 3-4 seconds per 25 emails.

What I really want is this:

delete every item in NoFlagMsg

which responds that every item doesn’t understand the command.  What’s the right syntax to do this in one fell swoop?

Best,
Jeff Porten



Entourage is an excellently-implemented AppleScript app in that 'whose clauses' can be used with every element in the application. But you can't do that when you put things into a (pure) AppleScript list, such as your NoFlagMsg list, because 'whose filters' have not been implemented in pure AppleScript lists and records. (Yet - we've been promised that they will be , some day.)  So in many circumstances, you could do this:

    delete every message of folder "Some Folder" whose flagged is false

That would do exactly what you want. BUT - elements have to been defined in that way - as elements of some object. The trouble with what you're attempting is that (current messages) is itself simply a list and a property of the application, not an object. So "every item" or something like that won't work - it just gives you the same list again, which doesn't have any properties of its own because it's not an Entourage object.

With (current messages) or (selection as list), you have to loop each item separately. But why are you selecting them if you really can delete every unflagged message in a folder? Who needs selection or "current messages"? Why are you using that syntax?  Instead, just select a FOLDER in the folder pane to display it in the main window (or its own window). Then do this:

    try -- you may  have nothing displayed, or something that "doesn't register", like Tasks list
        set theFolder to displayed feature of window 1   
       if class of theFolder � folder then erro number -128 -- enforce the error
    on error
        beep 2
    display dialog "You must have a older displayed in the front window!" buttons {"OK"} default button "OK" with icon 2
        return
    end try

    -- all Ok now

    delete every message of theFolder whose flagged is false

------

That will take less than 1 second. If you're daring, and trust yourself, you can even add:

    execute schedule "Empty Deleted Items"

but I'm not sure I'd do that myself. ;-)


Instead of
    
    
copy eachMsg to the end of NoFlagMsg

it will be a little faster to do:

    set end of NoFlagMsg to eachMsg

Not so much that you'd notice, unless there are several hundred messages involved, however.


--
Paul Berkowitz

Reply via email to