Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

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:
"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
 
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.