Re: New to applescript: year of
Re: New to applescript: year of
- Subject: Re: New to applescript: year of
- From: Christopher Nebel <email@hidden>
- Date: Thu, 28 Sep 2006 11:22:21 -0700
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:
This email sent to email@hidden