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

Announce incoming Mail message senders Apps
Instead of a simple ding sound, it's possible to have Mail tell you a little more about incoming messages using speech synthesis. Create the following AppleScript in Script Editor:
using terms from application "Mail"
  on perform mail action with messages newMessages
    repeat with newMessage in newMessages
      tell application "Mail"
        set senderName to (extract name from sender of newMessage)
        say "You've just received an email from " & senderName
      end tell
    end repeat
  end perform mail action with messages
end using terms from
Save it to something like ~/Library/Scripts/Mail Reader.scpt. In Mail, create a new rule to run the script on every incoming message.

[robg adds: You may wish to tweak the settings in the rule to limit announcements of things like mailing list messages and spam...]
    •    
  • Currently 2.50 / 5
  You rated: 4 / 5 (6 votes cast)
 
[18,717 views]  

Announce incoming Mail message senders | 24 comments | Create New Account
Click here to return to the 'Announce incoming Mail message senders' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Announce incoming Mail message senders
Authored by: Nobody Special on Jan 29, '08 08:14:39AM

If I wanted the script to announce the name of the sender and subject of the message, how would I modify the script? Thanks.



[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: bradbeattie on Jan 29, '08 08:24:50AM
set senderName to (extract name from sender of newMessage)
set sentSubject to (extract subject from newMessage)
say "You've just received an email from " & senderName
say sentSubject
Or, y'know, something like that.

[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: Nobody Special on Jan 29, '08 08:43:33AM

I tried it and receive an error message when compiling: "Syntax Error: Expected "," but found property."



[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: solipsism on Jan 29, '08 08:28:53AM

What is the best way to set up the rule so it doesn't read off all the emails you currently have in your inbox?



[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: Mac Berry on Jan 29, '08 08:56:46AM

It only does that if you apply the rule to the mailbox when you first set it up, i.e. tell it to run on all existing mail.



[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: peterkr on Jan 29, '08 08:59:40AM

Hi, I am using similar script for a long time. It reads RULE name instead of sender name (more practical for me):

using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with eachMessage in theMessages
try
-- If this is not being executed as a rule action,
-- getting the name of theRule variable will fail.
set theRuleName to name of theRule
set theText to "Mail from '" & theRuleName
say theText with Alex
end try
end repeat
end tell
end perform mail action with messages
end using terms from



[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: Fairly on Jan 29, '08 09:29:19AM

But the messages are already downloaded by then. Hardly a help. What you should do is use your connection (POP, whatever) to just download the headers and then you announce whatever you want.



[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: joshforman on Jan 29, '08 09:53:10AM

I believe the point is to tell you what the email is without having to switch to the mail app and possibly switch to the Inbox. If you're expecting an email, you'll know instantly if it's the one you want. That certainly sounds helpful to me, though, I suppose a Growl could also do the job.

---
Josh Forman

http://www.joshforman.com/



[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: porkchop_d_clown on Jan 30, '08 05:32:09AM

If you're constantly getting a stream of emails, having it announce when you get something important can be a big win.

I basically set up a Mail rule that only says the name of the sender if they are in my address book. You could easily extend that to only say the name if the mail is going to a special folder or soe on.

---
Everyone loves a clown, but no one will lend him money!



[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: dalemcbeath on Jan 29, '08 11:31:18AM

for the question of how to add a subject announcement, add these lines after the first say:

set subjectMsg to (subject of newMessage)
say "regarding " & subjectMsg

for some reason, doing the sets then using one long say garbles the voice, while splitting it up adds works well, at least on my intel imac 10.5



[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: groundswells on Jan 29, '08 11:38:06AM
The second "extract" doesn't work because its not extracting. Replace it with "get" and it will work, like this:
set sentSubject to (get subject of newMessage)

[ Reply to This | # ]
This will pause itunes, then read the subject, then start playing music again.
Authored by: raven42rac on Jan 29, '08 02:27:01PM
on perform_mail_action(info)
	tell application "iTunes"
		set isPlaying to player state is playing
	end tell
	tell application "Mail"
		set theMessages to |SelectedMessages| of info
		repeat with thisMessage in theMessages
			set AppleScript's text item delimiters to {""}
			set thisSender to sender of thisMessage as string
			set brkpos to offset of "

     

[ Reply to This | # ]
Store mail as audio file
Authored by: gjw on Jan 29, '08 02:51:47PM
The following script will turn e-mail into audio files stored in iTunes. The sender will be the artist and the track will be listed as part of a compilation album called MailTunes.

property kDeleteTempFiles : false -- not yet supported
property kMarkAsRead : true
property kReaderVoice : "Victoria"

on cleanBody(inBodyText)
	set theParagraphCount to number of paragraphs of inBodyText
	repeat with theIndex from 1 to theParagraphCount
		set theParagraph to paragraph theIndex of inBodyText
		if theParagraph = "-- " then
			return (paragraphs 1 through (theIndex - 1) of inBodyText) as string
		end if
	end repeat
	return inBodyText
end cleanBody

on formatDate(inDate)
	set theYear to year of inDate
	set theMonth to month of inDate
	set theDay to day of inDate
	set theDateString to (theYear * 10000) + (theMonth * 100) + theDay as string
	set theTime to time of inDate
	set theHour to (theTime / hours) div 1
	set theMinute to ((theTime - (theHour * hours)) / minutes) div 1
	set theSecond to theTime - ((theHour * hours) + (theMinute * minutes))
	set theHourString to theHour as string
	if theHour < 10 then set theHourString to "0" & theHourString
	set theMinuteString to theMinute as string
	if theMinute < 10 then set theMinuteString to "0" & theMinuteString
	set theTimeString to theHourString & theMinuteString & (theSecond as string)
	set theResult to theDateString & theTimeString
	return theResult
end formatDate

on findSaveLocation()
	tell application "Finder"
		if true then -- Test code to make our temp folder inside the temp directory.
			set theTempPath to path to temporary items as string
			set theRootFolder to folder theTempPath
		else
			set theRootFolder to folder "Desktop" of home
		end if
		
		try
			set theResult to folder "MailTunes" of theRootFolder
		on error
			set theResult to make new folder at theRootFolder with properties {name:"MailTunes"}
		end try
	end tell
	return theResult
end findSaveLocation

on processOneMessage(inMessage, inTempFolder)
	-- Copy the message data from Mail
	tell application "Mail"
		set theSender to sender of inMessage
		set theSenderName to extract name from theSender
		set theSubject to subject of inMessage
		set theDate to date sent of inMessage
		set theFileName to theSubject & " " & my formatDate(theDate) & ".aiff"
		set theBody to my cleanBody(content of inMessage)
	end tell
	
	display dialog theBody
	
	-- Save off the audio recording
	set thePath to inTempFolder & theFileName
	say theBody using "Victoria" saving to thePath
	
	-- Mark the message as read if we're supposed to
	if kMarkAsRead then tell application "Mail" to set read status of inMessage to true
	
	-- Build an alias list to import
	tell application "Finder" to set theFiles to file thePath as alias as list
	
	-- Import into iTunes
	tell application "iTunes"
		try
			set thePlaylist to playlist "MailTunes"
		on error
			set thePlaylist to make new playlist with properties {name:"MailTunes"}
		end try
		set theTrack to add theFiles
		set theConverted to convert theTrack
		repeat with theItem in theConverted
			set album of theItem to "MailTunes"
			set artist of theItem to theSenderName
			set compilation of theItem to true
			duplicate theItem to thePlaylist
		end repeat
		set theLocation to location of theTrack as string
		delete theTrack
	end tell
	
	-- Move the imported file to the trash
	tell application "Finder" to move file theLocation to trash
end processOneMessage

on run
	set theDestination to my findSaveLocation() as string
	tell application "Mail"
		-- First the primary inbox
		if the unread count of inbox > 0 then
			set theMessages to (every message of inbox whose read status is false)
			repeat with theMessage in theMessages
				my processOneMessage(theMessage, theDestination)
			end repeat
		end if
		-- Now handle other mailboxes
		set theMailboxes to every mailbox whose name is not "Junk"
		repeat with theMailBox in theMailboxes
			if (offset of "Junk" in (name of theMailBox as string)) = 0 then
				if the unread count of theMailBox > 0 then
					set theMessages to (every message of theMailBox whose read status is false)
					repeat with theMessage in theMessages
						my processOneMessage(theMessage, theDestination)
					end repeat
				end if
			end if
		end repeat
	end tell
	tell application "Finder" to move folder theDestination to trash
end run

using terms from application "Mail"
	on perform mail action with messages inMessageList
		set theTempFolder to my findSaveLocation() as string
		repeat with theMessage in inMessageList
			my processOneMessage(theMessage, theTempFolder)
		end repeat
		tell application "Finder" to move folder theTempFolder to trash
	end perform mail action with messages
end using terms from


[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: pauldy on Jan 29, '08 07:31:12PM

Wow, with the new voices in leopard this is actually a usefull tip and it works suprisingly well.



[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: tog on Jan 30, '08 03:55:24AM

But it's a shame that 10.4 has such rubbish voices!



[ Reply to This | # ]
Growl version
Authored by: Diggory on Jan 29, '08 09:15:42PM
Here's a similar script I use that uses Growl to notify of incoming mail. It launches the Address Book app (due to getting the picture of the sender, if available) - which some people find annoying, but I mitigate this by getting the Address Book app to be launched and hidden on login by the Accounts prefpane.

to getPictureForEmailAddress(personEmailAddress)
	tell application "Address Book"
		try
			set thePerson to (first person where the value of emails contains personEmailAddress)
			set thePiccy to image of thePerson
			return thePiccy
		end try
	end tell
end getPictureForEmailAddress



using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		-- 	display dialog ("Got here.  ")
		tell application "Mail"
			repeat with thisMessage in theMessages
				try
					-- If this is not being executed as a rule action,
					-- getting the name of theRule variable will fail.
					set theRuleName to name of theRule
					
					set theSubject to subject of thisMessage
					set theSender to sender of thisMessage
					set theJunkStatus to junk mail status of thisMessage
					set theReadStatus to read status of thisMessage
					
					--	We don't need to be notified of Junk
					if (theJunkStatus is true) then
						log ("junk")
						return
					end if
					
					--	Extract the email address and display name of the sender
					set theSendersName to extract name from sender of thisMessage
					set theSendersAddress to extract address from sender of thisMessage
					--	Find the sender's piccy
					set thePersonsPicture to my getPictureForEmailAddress(theSendersAddress)
					
					-- Check for spam not caught by Mail - but caught by Mail Provider's Anti-Spam.
					--	Your provider's warning string maybe different.
					if ((theJunkStatus is not true) and (theSubject does not contain "[**SPAM**]")) then
						if (theReadStatus is false) then
							tell application "GrowlHelperApp"
								set myAllNotesList to {"Mail Received"}
								register as application "Mail Notification Script" all notifications myAllNotesList default notifications myAllNotesList icon of application "Mail.app"
								try
									notify with name "Mail Received" title theSendersName description theSubject application name "Mail Notification Script" image thePersonsPicture
								on error the errorMessage -- user without picture in adressbook
									notify with name "Mail Received" title theSendersName description theSubject application name "Mail Notification Script" icon of application "mail.app"
								end try
							end tell
						end if
					end if
				end try
			end repeat
		end tell
	end perform mail action with messages
end using terms from

---
*****
monkeyfood software - http://www.monkeyfood.com

[ Reply to This | # ]

Announce incoming Mail message senders
Authored by: nukular on Jan 29, '08 10:45:47PM

What am I missing? I set it up with the rule that this must be run when the message received is less than 1 day old. I sent a test message and I simply got my regular email ding.

Yes I have told it to run the applescript I just saved.



[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: porkchop_d_clown on Jan 30, '08 05:37:28AM

I set mine to

if [all] the following conditions are met:
[sender is in my address book]
perform the following actions:
[run apple script] [~/Library/Scripts/Mail/SaySender]


---
Everyone loves a clown, but no one will lend him money!



[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: skorry1 on Jan 29, '08 11:13:38PM

Thanks. This is great! I set the rule so it only reads names in the address book or of previous recipients so that junk mail does not get read. Very useful as I don't have to leave my Word document or whatever to see who emailed me.



[ Reply to This | # ]
Everything old is new again...
Authored by: porkchop_d_clown on Jan 30, '08 05:40:40AM
Some guy named "porkchop_d_clown" first submitted this in.... 2003!

http://www.macosxhints.com/article.php?story=20030304111345916

---
Everyone loves a clown, but no one will lend him money!

[ Reply to This | # ]

Announce incoming Mail message senders
Authored by: mark hunte on Jan 30, '08 09:35:11AM
The Best comment I can Add here, is if this type of script idea is new to you,
Then you should join and read the forums site, This type of script for Mail is very old, but its clear that many people may not have seen them before.

There are many more scripts written and posted on the forums..
The Developer section is where normally the Applescripts fall into, but you can view all threads using the sites 'new posts' button.

http://forums.macosxhints.com/

---
mh

[ Reply to This | # ]

How to avoide spam messages to be announced?
Authored by: sherlokk2 on Feb 01, '08 05:38:58AM

Hi, for me this is a very useful hint. The only problem is that I have several rules in Mail for deleting spam and the last rule is to start this script. The unwanted messages are deleted properly but they are still announced. Any idea?



[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: bryaneh on Mar 08, '08 08:01:20AM

Anyone having issues with Mail dieing when it starts executing this script? Intermittently it gets half-way done speaking and then Mail dies. I've repaired permissions, reinstalled the combo 10.5.2, rebuilt all of my mailboxes, etc.



[ Reply to This | # ]
Announce incoming Mail message senders
Authored by: pet on Sep 24, '08 03:52:53PM

I love the script and have found it very useful but my mail also crashes periodically. Is there something I can do about this?

pet



[ Reply to This | # ]