Re: How to get every message that meets a condition in Mail
Re: How to get every message that meets a condition in Mail
- Subject: Re: How to get every message that meets a condition in Mail
- From: kai <email@hidden>
- Date: Tue, 04 Nov 2003 22:27:00 +0000
on Tue, 4 Nov 2003 00:32:45 -0800, Christian Boyce wrote:
>
On Nov 3, 2003, at 4:49 PM, kai wrote:
>
>
> You'd probably be better off directly comparing date values, Christian. This
>
> works for me:
>
>
>
> --=========================
>
>
>
> set today to current date
>
> set today's time to 0
>
> tell application "Mail"
>
> set theMessages to messages of mailbox "Sent Messages" of account "kai"
>
> whose date sent >= today
>
> end tell
>
>
Wow. Nice.
>
>
Your "set today's time to 0" is something new to me. That will help me
>
down the road.
Great. :-)
As you might have guessed from that, there are a few similar things one can
do to manipulate dates. Here are a few simple examples:
---------------------
set d to current date
d --> date "Tuesday, November 4, 2003 10:16:14 pm"
set d's year to 2002
d --> date "Monday, November 4, 2002 10:16:14 pm"
set d's month to December
d --> date "Wednesday, December 4, 2002 10:16:14 pm"
set d's time to 9 * hours + 25 * minutes
d --> date "Wednesday, December 4, 2002 9:25:00 am"
set d's day to 24
d --> date "Tuesday, December 24, 2002 9:25:00 am"
set d's time to 30 * hours
d --> date "Wednesday, December 25, 2002 6:00:00 am"
set d's time to 7 * days
d --> date "Wednesday, January 1, 2003 12:00:00 am"
set d's day to 45
d --> date "Friday, February 14, 2003 12:00:00 am"
---------------------
Obviously, the format of your results may differ depending on your system's
date and time settings.
The last 3 examples show how a date is adjusted when a value exceeds the
maximum for a particular date/time unit (> 24 hours, > 28/29/30/31 days,
etc). In fact, I suppose you could use this feature to calculate certain
values - such as:
---------------------
on daysIn(m)
set d to date (m as string)
tell 32
set d's day to it
it - (d's day)
end tell
end daysIn
daysIn(November)
--> 30
---------------------
Probably not the best way to achieve such a result, but hopefully it
demonstrates the point. (Personally, I never got much further with the
mnemonic rhyme than "Thirty days hath September, all the rest I can't
remember...")
>
I had constructed something similar this evening, but not as elegantly:
>
>
set today to date string of (current date) as string
>
set midnight to "12:00:01 AM"
>
set today to (today & " " & midnight)
>
set today to date (today)
>
and then I compared dates in Mail as you did.
>
>
Setting the time to 0 is a lot nicer than doing what I did. Thanks a
>
lot.
You're most welcome, Christian.
BTW, it's also quite a bit faster here. If we ignore the time it takes to
get the current date (which is common to both methods), setting the time is
about 25 times faster than using string concatenation and coercions.
---
kai
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.