New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Applescript for Mail


Post Reply New Thread Subscribe

 
Thread Tools
pyth

 
Member Since: Sep 14, 2009
Posts: 1
pyth is on a distinguished road

pyth is offline
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
QUOTE Thanks
Collin Bl

 
Collin Bl's Avatar
 
Member Since: Apr 07, 2009
Location: Napier NZ
Posts: 3,281
Collin Bl is a jewel in the roughCollin Bl is a jewel in the roughCollin Bl is a jewel in the rough
Mac Specs: 27 iMac i5, MBP 13 & iMac 20, 2TB dual TC, AppleTV, iPh4S

Collin Bl is offline
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.
QUOTE Thanks
nabl

 
nabl's Avatar
 
Member Since: Dec 13, 2007
Location: United States of America
Posts: 256
nabl has a spectacular aura about
Mac Specs: 2.1GHz MacBook with 4GB RAM, Mac OS X 10.6, iLife and iWork 09

nabl is offline
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
QUOTE Thanks
technologist

 
Member Since: Mar 30, 2004
Location: USA
Posts: 4,744
technologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond repute
Mac Specs: 12" Apple PowerBook G4 (1.5GHz)

technologist is offline
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.
QUOTE Thanks
Drudeken

 
Member Since: Aug 26, 2010
Posts: 1
Drudeken is on a distinguished road

Drudeken is offline
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
QUOTE Thanks

Post Reply New Thread Subscribe


« new to programing | crt1.o for x86_64 »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Logic Express and Applescript via GUI Scripting albertaurus Music, Audio, and Podcasting 0 04-09-2009 01:13 PM
Applescript for Toggling Energy Saver Presets Unifier OS X - Operating System 1 03-17-2008 08:58 PM
Run applescript on start-up slugzzz Running Windows (or anything else) on your Mac 3 09-11-2007 01:51 AM
[ANN] New comprehensive AppleScript book hanaan OS X - Development and Darwin 0 11-06-2004 07:28 PM
Looking for AppleScript help tommyabroad OS X - Operating System 2 04-14-2004 12:51 AM

All times are GMT -4. The time now is 11:12 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?