Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Use Speech to announce new Mail messages' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use Speech to announce new Mail messages
Authored by: GlowingApple on Mar 31, '05 09:32:53PM
So just in case anyone is still looking at this thread, here is my latest revision of the script (I'm running it on Panther):

(*
Speak New Mail Script
Origional code (Copyright © 2003 Apple Computer, Inc.) taken from Apple sample code at 
/Library/Scripts/Mail Scripts/Script Menu/Speak Sender and Subject___ctl-s.scpt

Origional modification by hotcocoa and several other modifications taken from 
http://www.macosxhints.com/article.php?story=20040422104515106&query=speak+mail.

Final modification by Jayson Kempinger 2005
*)

(*
This script runs when Mail.app gets new mail.  Each mail message is parsed for name and subject, iTunes is paused by
manner of fading out (if it is running), the message notification is spoken, and iTunes is resumed to it's prior state.

Use this script in a Mail.app rule.
Precede it with a rule "If any, Message is junk mail, then Stop evaluating rules" to prevent this script from speaking
junk mail as well.
*)

on perform_mail_action(info)
	--if iTunes is playing, fade out
	set reactivate to false
	tell application "System Events"
		if the exists process "iTunes" then
			tell application "iTunes"
				if player state is playing then
					set orig_vol to sound volume of application "iTunes"
					repeat
						set snd to sound volume of application "iTunes"
						if snd is less than or equal to 30 then
							exit repeat
						end if
						set sound volume of application "iTunes" to (snd - 5)
						delay 0.1
					end repeat
					set reactivate to true
				end if
			end tell
		end if
	end tell
	
	tell application "Mail"
		--get set of messages as objects
		set selectedMessages to |SelectedMessages| of info
		--count them
		set numMessages to the count of selectedMessages
		--if there are more than five messages, then don't say each one, just say the number of new mail messages
		if numMessages is less than or equal to 5 then
			repeat with eachMessage in selectedMessages
				
				-- seperate name from email address
				set theFromAddress to sender of eachMessage
				set theBreak to " <"
				set nameEnd to the offset of theBreak in theFromAddress
				if nameEnd is not 0 then
					set fromPerson to (characters 1 through (nameEnd - 1) of theFromAddress) as string
				end if
				
				-- determine if this is a reply or forward
				set theSubject to subject of eachMessage
				if theSubject contains "re:" or theSubject contains "Re:" then
					set introText to "Reply from "
				else if theSubject contains "Fwd:" or theSubject contains "Fw:" or theSubject contains "fwd:" or theSubject contains "fw:" then
					set introText to "Forwarded mail from "
				else
					set introText to "New mail from "
				end if
				
				--combine parts and say it
				say introText & fromPerson & ".  Subject is " & theSubject & "." --using "Voice Name"
			end repeat
		else
			say numMessages & " new mail messages."
		end if
	end tell
	
	if reactivate is true then
		tell application "iTunes"
			repeat
				set snd to sound volume of application "iTunes"
				if snd is greater than or equal to orig_vol then
					exit repeat
				end if
				set sound volume of application "iTunes" to (snd + 5)
				delay 0.1
			end repeat
		end tell
	end if
end perform_mail_action

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."

[ Reply to This | # ]