Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New to applescript: year of



On Sep 27, 2006, at 9:48 PM, Yvan KOENIG wrote:

It's the first thing I tried but it failed.

set {laSource, laDestination} to {"zzz", "xyz"}

tell application "Mail"
set k to count of messages of mailbox laSource
if k > 0 then
repeat with myMessage in (every message of mailbox laSource)
set my_message to contents of myMessage
if year of (get date received of my_message) = 2005 then move my_message to mailbox laDestination
end repeat
end if
end tell

In general, it's not safe to modify a collection while you're iterating over it.  It can be done, but you have to be careful about how you do it.  One way is to use an explicitly index-based loop and count backwards ("repeat with i from (count messages) to 1 by -1" ).  Another way is to get the list of messages into a local variable and then iterate over that ("set ml to every message; repeat with m in ml"), though that does not work for collections that use index-based specifiers, and it uses more memory at once.  A third way -- the best one, assuming it works -- is to not use a loop at all and use a "whose" specifier, though how to do that in this particular case is a bit circuitous thanks to the "year of" problem ("move every message whose date received is greater than date "1/1/2005" and whose date received is less than date "1/1/2006").


--Chris Nebel
AppleScript Engineering

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden

This email sent to email@hidden

References: 
 >Re: New to applescript: year of (From: Yvan KOENIG <email@hidden>)
 >Fwd: New to applescript: year of (From: Yvan KOENIG <email@hidden>)
 >Re: New to applescript: year of (From: Francis Derive <email@hidden>)
 >Re: New to applescript: year of (From: Emmanuel <email@hidden>)
 >Re: New to applescript: year of (From: Yvan KOENIG <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.