Hunter Ford Hunter Ford

Growl Notifications for Apple Mail on Mac OS X

UPDATE: You can grab a beta version of 64-bit Growl 1.2 from the Growl beta site.
GrowlMail is broken on Mac OS X Snow Leopard (10.6). The dev team for Growl has a fix in the works, but I use Prowl and like to have notifications go to my iPhone when I'm not at my computer. So in the meantime, here is my solution.

Screen shot 2009-09-02 at 9.51.22 AM

I was originally inspired by James Higgs.

You first want to create a new AppleScript using AppleScript Editor and save it somewhere logical. I used /Library/Scripts/Mail Scripts/Rule Actions/Growl.scpt Below is the code:

-- Growl Alerts in Mail
-- Hunter Ford [http://www.cupcakewithsprinkles.com]
-- This script arises from the lack of any Growl Support in Mac OS X Snow Leopard (10.6)
-- Code inspired by and adapted from James Higgs [http://blog.jameshiggs.com/2009/08/28/growlmail-on-snow-leopard-a-temporary-fix/] as well as those mentioned.

tell application "GrowlHelperApp"
	-- Make a list of all the notification types
	-- that this script will ever send:
	set the allNotificationsList to {"New Email"}

	-- Make a list of the notifications
	-- that will be enabled by default.
	-- Those not enabled by default can be enabled later
	-- in the 'Applications' tab of the growl prefpane.
	set the enabledNotificationsList to {"New Email"}

	-- Register our script with growl.
	-- You can optionally (as here) set a default icon
	-- for this script's notifications.
	register as application "Mail" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Mail"
end tell

-- Mail Rule Trigger
--
-- Source: Benjamin S. Waldie [http://www.mactech.com/articles/mactech/Vol.21/21.09/ScriptingMail/index.html]
using terms from application "Mail"
	on perform mail action with messages theSelectedMessages for rule theRule
		repeat with thisMessage in theSelectedMessages
			-- Process the current message

			-- Grab the subject and sender of the message
			set growlSubject to subject of thisMessage
			set growlSender to my ExtractName(sender of thisMessage)

			-- Use the first 100 characters of a message
			set growlMessage to (content of thisMessage)
			set growlLength to (length of growlMessage)

			if growlLength > 100 then
				set growlMessage to (characters 1 through 100 of growlMessage) & "…"
			end if

			set growlMessage to growlSubject & "

" & growlMessage

			-- Send a Notification
			tell application "GrowlHelperApp"
				notify with name "New Email" title growlSender description growlMessage application name "Mail"
			end tell
		end repeat
	end perform mail action with messages
end using terms from

-- *ExtractName*
--
-- gathers the name portion from the "From: " line
--
-- Source: robJ [http://forums.macosxhints.com/archive/index.php/t-19954.html]
to ExtractName(sender_)
	if sender_ begins with "<" then
		return text 2 thru -2 of sender_
	else
		set oldTIDs to text item delimiters
		try
			set text item delimiters to "<"
			set name_ to first text item of sender_
			set text item delimiters to oldTIDs
		on error
			set text item delimiters to oldTIDs
		end try
		return name_
	end if
end ExtractName

Run this first in the AppleScript Editor. As this is what will "register" the notification with Growl. Click the green "play" button that says "Run".

Screen shot 2009-09-01 at 10.46.18 PM

Then you want to create a new rule in mail that will run this script on every message that comes in.

Screen shot 2009-09-01 at 4.45.20 PM

Make sure to select "Don't Apply" that way you don't flood your screen with tons of Growl notifications.

Screen shot 2009-09-01 at 4.53.15 PM


Comments

  • Barry Allard

    **One major gocha**: Mail.app executes new mail notifications on the main_thread, beachballing Mail until **every** notification has been shown. Instead, they should use a serial dispatch queue.
  • Barry Allard

    Way better than waiting for the always broken GrowlMail to get updated.
  • Andy

    Very nice, thank you!!
  • Alain Lambrette

    Tanks for this script, from belgium
  • Maymers

    This worked great, thanks!!
  • Markus

    Awesome! Thank you!
  • Cat

    This is great, however I am running into the same issue a few others have: Since my new mail is not automatically selected, Growl is displaying whatever old message is currently selected in Mail. Hope someone can think of a workaround.
  • Ben

    Incredible !! Thanks you so much
  • Mamadoo

    thank you very much work great
  • Paul Pleavin

    Works great and so easy to do Thank you
  • Stuka

    Thank you!
  • Wassim

    Thank you for this! I have modified the script to add the ability to display the sender's photo (if it exists in the address book). Otherwise, it displays the sender place holder image from Mail.app. I also incorporated Ryan's tip about summarising multiple messages so they do not fill the screen. I uploaded the script to http://wjabi.net/Mail2Growl.scpt I would love to hear if it works well for you. [wassim dot jabi at gmail dot com]
  • Jorge

    Much thanks! Works as expected on Snow Leopard. You're da bomb! ;)
  • Guillaume Laurent

    I installed this following up on the announcement that Growl would become a full-blown app and therefore that GrowlMail would no longer be supported. Thank you, it works perfectly with OS X Lion GM. I don't seem to have the "previously selected mail" problem which other commenters describe.
  • clarusmoof

    So I've a few other folks having the issue of only the previous email showing when new emails are received instead of the new email. If I missed it but was there a fix for this in the code? Otherwise a great fix. Thanks
  • TheRobBrennan

    This is a G-R-E-A-T tip. Thanks for sharing =)
  • Ryan

    Thanks very much for this. I've edited it slightly to coalesce updates with &gt; 5 new emails as follows: on perform mail action with messages theSelectedMessages for rule theRule set N to count items of theSelectedMessages if (N &gt; 5) then set multipleDescription to "" &amp; N &amp; " new messages" tell application "GrowlHelperApp" notify with name "New Email" title "New Mail" description multipleDescription application name "Mail" end tell else repeat with thisMessage in theSelectedMessages ... This avoids the problem of multiple growls for your existing mail when you set the rule up as well.
  • Andrea

    This is absolutely great! Thank you so much. Very well done.
  • andrep

    Works for me too. Thanks very much indeed for posting this!
  • *m

    Works great! Thank you very much :) *m
  • Nathan

    Sweet. Thanks a lot.
  • Carlos

    Nice. Thanks.
  • Bill

    Very cool. Thank you!
  • Nick Gushlow

    Works brilliantly thanks.
  • Stephen

    For those complaining about the line numbers, you can click the icon in the upper right corner to get the source. And I have the previous e-mail problem too. Weird. I think it's more an AppleMail issue.
  • Tom Bates

    Nice One :)
  • Krakmann

    OMG. Thanks. A. Lot.
  • Erik Rapprich

    Thanks this is awesome. I'm def. passing this along.
  • Fred

    Hi, Same issue as a few others. I get the notification right but for the mail before last. Any idea ?
  • katmoda

    great work! I was missing this when i went to SL Works well for what i wanted! Thank you for sharing!
  • Gabi

    Oh!!! Really, really, really useful!!!! Thanks a lot!!! ;)
  • Chris J. Politzki

    Nice work... was getting frustrated that I couldn't see when I was getting a new email message. Thanks for posting this!
  • DiSH

    Thanks! It's great!
  • Dan

    I am seeing the same issue with the script that Chris, Nick, and Achal are seeing. If there is nothing in my inbox, I get no growl notification. If I have stuff in the inbox, for a new mail, it's showing the info from the previous email. Strange.
  • Ulf Bierkmper

    Thanks, thanks, thanks... :-) Great job!
  • Wiz

    Works GREAT!!! Just ran the newest Apple update and got real upset when Growl Mail was broken again! You saved me from going nuts! Thank you so much!
  • Mauricio Clauzet

    Excelent, thanks for sharing, it works great here!
  • kippiler

    wow, you are awesome!!!! it works great! thanks a lot!!!
  • Madhavi

    Thanks for your script! Worked like a charm! Ever since the new Snow Leopard upgrade, and Growl Mail went bust, I have been so frustrated! But now I found your script and things are great once again!
  • Chris

    Absolutely awesome! code works perfectly and is much simpler than many other workarounds I have already tried. Thanks!
  • RedEye

    Works Fine!!! Thanks a lot
  • Jimmy

    worked like a charm, but lmao i got 1400 mails in my mailbox after that grows was opening each one so i had to quit it hehe. thanks
  • Sascha

    Works great, just except for the clicking issue Cosimo mentioned. Annoying that after every OSX update Growl doesn't work properly any more...
  • Josh

    works like a charm! Thanks so much!
  • chainaddicted

    works great, thx, marius
  • Rod

    Hunter - you just saved me! Growl mail is broken again with the lated patch from Apple, (1.6.2) but your script is working perfectly! Thanks for taking the time to write it and share it with perfect instructions!
  • Rick

    Does not work. Followed the steps exactly, no actions in Mail. First clue something was wrong was that I wasn't asked if I wanted to apply this rule after I created and saved it.
  • Tim

    I tried compiling the script and got lots of end of line errors highlighting the quotation marks around application "Mail" and so on. The script saved fine, and I ran the registration - apparently ok, in that nothing appeared to happen - yet when I try and compile the script, I still get eo line errors, and nothing happens when mail arrives.. I copied the script on to the clipboard which I emptied in to the app script editor...any thoughts?
  • Hunter Ford

    @T If you hover your mouse inside the code block, at the top right, you should see a number of icons. These will allow you to view the source without the line numbers. There's also an option to copy the code to your clipboard.
  • Wayne

    Outstanding. Thanks.
  • T

    um wtf? the way you copy and pasted it, the line numbers show up so i get a line number in front of every line.... i have to manually remove it now, that is awful.... could you copy and paste it without the line numbers? i know it "looks cooler" but it isn't practical.
  • T

    thanks this is great! :o)
  • Bob Proctor

    Awesome! Thanks so much for this script. It works fine.
  • xmoov

    No thats what I call xmoov :-) Good lookin out!
  • Nick

    I'm having the same issue as Chris... Whenever I get an email, it's just display the most recent selected email. Any idea what changes to the script need to be made?
  • Chris

    It seems to only want to display the notification for the currently selected email and repeats the same number of times as there are new emails.
  • Brian Larson

    This rules!! Thanks for posting this. It worked perfectly.
  • Dorian Grey

    Absolutely awesome! Thank you very much!
  • Jared

    Thanks so much for this! I just installed SL and found this issue with Growl and Mail and it's now fixed with your script. :)
  • Achal

    Thanks so much for the script. It worked wonderfully just a small glitch on my mac. It shows the details of one previous message rather than that of the new message. (I am synching with an Microsoft server 2007).
  • Hunter Ford

    @Cosimo I'm afraid not. At the moment, only Cocoa and Carbon apps can track clicks on Growl alerts using the Growl Application Bridge. Applescript just ain't that fancy.
  • Cosimo

    Almost perfect! It just need to send the command to open the new message once the growl notification is clicked... would it be possible to add this to the apple script?
  • James Higgs

    Awesome. Thanks for doing that, Hunter. I may never use GrowlMail again!
  • Detlef Httemann

    Thanks - works fine!