Mac AppleScript - Wait until mail finishes checking new mail

NorthDakota91

macrumors member
Original poster
Sep 3, 2011
86
0
Italy
Hello all! I have a (probably dumb) question: I'd like to write a simple applescript that would force mail to check for new mail and then tell me how much unread messages i have. This is what i've done so far (not much :p):

Code:
tell application "Mail"
	check for new mail
	set unreadMailCount to unread count of inbox
end tell

say "Unread messages: " & unreadMailCount as text
The code works but it seems that the script doesn't wait until Mail.app finishes checking for new mail, so when I receive new messages, the script still reports 0. What can I do?
 
Last edited:

Partron22

macrumors 68030
Apr 13, 2011
2,565
756
Yes
"check for new mail" doesn't return a result you can wait for.

So you have to call check for new mail repeatedly until the new mail count stops changing.
Here's an example of how to do that: check email
 

NorthDakota91

macrumors member
Original poster
Sep 3, 2011
86
0
Italy
So you have to call check for new mail repeatedly until the new mail count stops changing.
Here's an example of how to do that: check email
Thank you for the link, I've already seen this tutorial but in my particular case this does not apply unfortunately because I'd like the script to be executed at login time only (forgot to mention, sorry for that) :(

"check for new mail" doesn't return a result you can wait for.
Bummer :( Well, I think that I'll just use a delay then

Again, thank you very much for your time!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.