Writing an Applescript for New Mail

Discussion in 'Mac Programming' started by pyth, Sep 14, 2009.

  1. pyth macrumors member

    Mar 7, 2008
    I'm trying to write a script that does a few things on wakeup every morning. So far, I've figured out how to open Safari with a particular URL, play a playlist in iTunes and get new mail. However, I'm having trouble with a little feature I thought would be nice. Here's what I've got so far:

    say "Hey, wake up. I've got news for you." using "Ralph"
    tell application "Safari"
    open location "http://online.wsj.com/home-page"
    end tell
    tell application "Mail"
    check for new mail
    mailbox "inbox"
    exists unread count
    If true then
    say "You've got mail" using "Ralph
    quit application
    end tell

    However, it's not working. I'd like to set it where after it checks for new mail, it says "You've got mail" using the voice "Ralph". I can't figure out for the life of me how to do that. I thought that I'd have to use a conditional, but it's not working. If you've got any ideas, I'd really appreciate them.

  2. mysterytramp macrumors 65816


    Jul 17, 2008
    Mail's a bitch to script.

    This bit seems to work:

    tell application "Mail"
    	set x to unread count of inbox
    	check for new mail
    	delay 3
    	set y to unread count of inbox
    end tell
    if x = y then
    	say "You have no new messages, bub" using "Ralph"
    	say "You've got mail" using "Ralph"
    end if
    You know you need to set Mail to check for mail only manually for this script to work (or at least work well)

    I'll leave it to you to add the other bits.

  3. pyth thread starter macrumors member

    Mar 7, 2008

Share This Page