Results 1 to 5 of 5
  1. #1
    Applescript for Mail

    Member Since
    Sep 14, 2009
    Posts
    1
    Applescript for Mail
    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"
    activate
    check for new mail
    mailbox "inbox"
    exists unread count
    If true then
    say "You've got mail" using "Ralph
    else
    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.

    -Alex

  2. #2
    Applescript for Mail
    Collin Bl's Avatar
    Member Since
    Apr 07, 2009
    Location
    Napier NZ
    Posts
    3,291
    Specs:
    27 iMac i5, MBP 13 & iMac 20, 2TB dual TC, AppleTV, iPh4S
    Perhaps start of with an existing Script from the collection and modify it to do what you want. From the bit of playing around that i have done the above seems out of order. Putting above in Script Editor and compiling gives a syntax error.

  3. #3
    Applescript for Mail
    nabl's Avatar
    Member Since
    Dec 13, 2007
    Location
    United States of America
    Posts
    256
    Specs:
    2.1GHz MacBook with 4GB RAM, Mac OS X 10.6, iLife and iWork 09
    This might be a little more complex than you wanted, but I did manage to come up with some code that finds whether you have any unread messages:
    Code:
    tell application "Mail"
    	-- this returns a list with the unread counts of every mailbox
    	set unreadCounts to unread count of every mailbox
    	-- assume there are no new messages
    	set areNewMessages to false
    	-- check each unread count individually
    	repeat with i from 1 to the count of unreadCounts
    		set currentUnreadCount to item i of unreadCounts
    		if currentUnreadCount is greater than 0 then
    			-- this mailbox has one or more unread messages
    			set areNewMessages to true
    		end if
    	end repeat
    	if areNewMessages is true then
    		-- there are unread messages, so say an alert
    		say "You've got mail!" using "Ralph"
    	else
    		-- there are no new messages, so quit the application
    		quit
    	end if
    end tell

  4. #4
    Applescript for Mail

    Member Since
    Mar 30, 2004
    Location
    USA
    Posts
    4,744
    Specs:
    12" Apple PowerBook G4 (1.5GHz)
    As an alternative, you could set up a filter ("Rule") in Mail that runs a a simple "Say..." script whenever any message is received.

    Though this will run every time you get mail throughout the day, not just in the morning.

  5. #5
    Applescript for Mail

    Member Since
    Aug 26, 2010
    Posts
    1
    Late, but its what I came up with
    Code:
    tell application "Mail"
    	if (count of (every mailbox in every account where unread count is greater than 0)) is greater than 0 then
    		activate
    		tell current application
    			say "You've got mail!" using "Ralph"
    		end tell
    	else
    		quit
    	end if
    end tell

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 01-23-2015, 03:39 PM
  2. Simple AppleScript for mail
    By JosCiv in forum OS X - Apps and Games
    Replies: 10
    Last Post: 07-27-2013, 04:09 PM
  3. Mail button and AppleScript
    By JSS in forum OS X - Development and Darwin
    Replies: 4
    Last Post: 08-27-2011, 01:28 PM
  4. More AppleScript Help
    By Babkockdood in forum OS X - Development and Darwin
    Replies: 5
    Last Post: 02-14-2010, 04:28 AM
  5. Applescript for sending selection as new Mail
    By gurth4ng in forum OS X - Development and Darwin
    Replies: 3
    Last Post: 09-24-2009, 10:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •