Resolved AppleScript - Wait until mail finishes checking new mail

Discussion in 'Mac Programming' started by NorthDakota91, Nov 15, 2011.

  1. NorthDakota91, Nov 15, 2011
    Last edited: Nov 15, 2011

    NorthDakota91 macrumors member

    Sep 3, 2011
    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):

    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 finishes checking for new mail, so when I receive new messages, the script still reports 0. What can I do?
  2. Partron22 macrumors 68020


    Apr 13, 2011
    "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
  3. NorthDakota91 thread starter macrumors member

    Sep 3, 2011
    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) :(

    Bummer :( Well, I think that I'll just use a delay then

    Again, thank you very much for your time!

Share This Page