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

Growl Notification from Mail.app with Sender Photos Apps
You can use an AppleScript to send a notification to Growl whenever new messages arrive in Mail.app. The script also includes the image of the sender from your Address Book as the icon of the Growl notification. Works in Snow Leopard and Lion.

I adapted a script written originally by Hunter Ford. I added the ability to include the image of the sender from the Address Book (if it exists). Britney F. helped me solve a couple of bugs -- Many thanks!

First you have to be using Mail.app and the latest version of Growl.

You can download the script from here and place in your /Library/Scripts folder or anywhere you wish.

To use this script, you have to add a rule in Mail.app to run the script for all new messages.

In Mail.app choose Preferences » Rules » Add New Rule. Then set the condition to 'Every Message' and the action to 'Run AppleScript' then choose the Mail2Growl.scpt from the folder you saved it in.

Whenever you get a new message, a Growl notification will appear with the image of the sender or a placeholder image if you do not have his/her image in your Address Book.

Here's the script (save it as Mail2Growl.scpt):
-- Mail2Growl
-- Growl Alerts in Mail
-- Wassim Jabi [http://wjabi.net]
-- Modified from the excellent script by Hunter Ford [http://www.cupcakewithsprinkles.com]
-- If it exists, this script sends the photo of the sender to Growl from the address book. Otherwise, it sends the sender place holder image from Mail.app.
-- Original script found at [http://hunterford.me/growl-notifications-for-apple-mail-on-mac-os-x/]
-- This script uses a tip to summarise many messages by "Ryan" in the comments section at [http://hunterford.me/growl-notifications-for-apple-mail-on-mac-os-x/]
-- This script also used tips from [http://www.macosxtips.co.uk] for finding photos in the Address Book
-- This script arises from the lack of any Growl Support in Mac OS X Snow Leopard (10.6) or Lion (10.7)
-- 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
    set N to count items of theSelectedMessages
    if (N > 5) then
      set multipleDescription to "" & N & " new messages"
      tell application "GrowlHelperApp"
        notify with name "New Email" title "You have " & N & " new messages." description " " application name "Mail"
      end tell
    else
      repeat with thisMessage in theSelectedMessages
        -- Process the current message
        
        -- Grab the subject and sender of the message
        set growlSender to my ExtractName(sender of thisMessage)
        try
          set growlPhoto to my getPhotoFromAddressBook(my ExtractEmailAddress(sender of thisMessage))
        on error
          set growlPhoto to read POSIX file "/Applications/Mail.app/Contents/Resources/SenderImagePlaceholder.png" as "TIFF"
        end try
        set growlSubject to subject of thisMessage
        set growlTitle to growlSender & return & growlSubject
        -- Use the first 100 characters of a message
        set growlDescription to (content of thisMessage)
        set growlLength to (length of growlDescription)
        
        if growlLength > 100 then
          set growlDescription to "" & (characters 1 through 100 of growlDescription) & " "
        end if
        
        -- Send a Notification
        tell application "GrowlHelperApp"
          try
            notify with name "New Email" title growlTitle description growlDescription application name "Mail" image growlPhoto
          on error
            set growlPhoto to (read POSIX file "/Applications/Mail.app/Contents/Resources/SenderImagePlaceholder.png" as "TIFF")
            notify with name "New Email" title growlTitle description growlDescription application name "Mail" image growlPhoto
          end try
        end tell
      end repeat
    end if
  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_ as string
  end if
end ExtractName

-- *ExtractEmailAddress*
--
-- gathers the email address portion from the "From: " line
--
-- Source: robJ [http://forums.macosxhints.com/archive/index.php/t-19954.html]
to ExtractEmailAddress(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 email_ to second text item of sender_
      set text item delimiters to oldTIDs
    on error
      set text item delimiters to oldTIDs
    end try
    return email_ as string
  end if
end ExtractEmailAddress


to getPhotoFromAddressBook(sender_)
  set photo_ to read POSIX file "/Applications/Mail.app/Contents/Resources/SenderImagePlaceholder.png" as "TIFF"
  try
    tell application "Address Book"
      set photo_ to image of people whose value of emails contains sender_
    end tell
  on error
    set photo_ to read POSIX file "/Applications/Mail.app/Contents/Resources/SenderImagePlaceholder.png" as "TIFF"
  end try
  return photo_
end getPhotoFromAddressBook

[crarko adds: Tested briefly, seemed to work OK in 10.6.8. It looks like the most recent version of Growl (for Lion) is in the Mac App Store for US $1.99. The option to build it from source is still available as well.]
    •    
  • Currently 4.00 / 5
  You rated: 4 / 5 (4 votes cast)
 
[6,711 views]  

Growl Notification from Mail.app with Sender Photos | 7 comments | Create New Account
Click here to return to the 'Growl Notification from Mail.app with Sender Photos' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Growl Notification from Mail.app with Sender Photos
Authored by: Aikwaar on Feb 09, '12 08:14:50AM

I have Mail Version 5.2 (1257) and Growl 1.3.3 in Lion and this seems not to work



[ Reply to This | # ]
Growl Notification from Mail.app with Sender Photos
Authored by: dijon on Feb 09, '12 08:31:08AM

I am running the newest versions of both OS X and Growl, on a MacBook Pro that is a couple of weeks old, and I noticed that the script didn't work properly until I placed it into the '/Library/Scripts/Mail\ Scripts/' path. Otherwise (in /Library/Scripts path), it would only open my Address Book.app. I haven't tried to place the script anywhere else, so I don't know of any problems with doing that.



[ Reply to This | # ]
Growl Notification from Mail.app with Sender Photos
Authored by: blgrace on Feb 10, '12 12:05:33PM

I'm also running Mail v5.2 and Growl V1.3 (built from source)

I have the script in /Library/Scripts/Mail Scripts/
Scripts also just opens my AddressBook.app

I was reading through the AppleScript and it looks for GrowlHelperApp ?



[ Reply to This | # ]
Growl Notification from Mail.app with Sender Photos
Authored by: jgregc on Feb 10, '12 09:06:58AM

You may have to pull the script into the Applescript editor and run it once for the script to work in mail. Otherwise it won't set itself up in Growl (at least the latest growl for Lion), due to the position of the first growl tell in the script.

Once you run it from the Applescript editor you should find Mail as an enabled application in Growl and it should work fine wherever you put it as long as you set the script up with the mail rule. At least this is what happened in my case when I downloaded the script @11:30am or so.



[ Reply to This | # ]
Growl Notification from Mail.app with Sender Photos
Authored by: Anonymous on Feb 11, '12 04:59:55AM
Using Growl 1.3.3 from the Mac App Store and Mail 5.2 (1257) on Lion 10.7.3, it only worked when I change tell application "GrowlHelperApp" to tell application "Growl"

[ Reply to This | # ]
Growl Notification from Mail.app with Sender Photos
Authored by: rcmit on Feb 14, '12 09:54:43AM

I have Mail Version 5.2 (1257) and Growl 1.3.3 in Lion. I used the downloaded script which used the application "Growl" and not "GrowlHelperApp", and I loaded the script into the Applescript editor and ran it. The Mail app also shows in the list of apps in Growl preferences. Given all this I'm still unable to get it to work. Any suggestions would be welcome!



[ Reply to This | # ]
Growl Notification from Mail.app with Sender Photos
Authored by: paxdruid on Feb 16, '12 09:42:13PM
Okay, for all those Lion + Growl 1.3.3+ users, I had a tinker with the script in conjunction with the sample Applescript provided by the Growl Team. Basically just replace 'tell application "GrowlHelperApp"' with 'tell application id "com.Growl.GrowlHelperApp"'.

Here's a replacement Mail2Growl.scpt:


-- Mail2Growl
-- Growl Alerts in Mail
-- Wassim Jabi [http://wjabi.net]
-- Modified from the excellent script by Hunter Ford [http://www.cupcakewithsprinkles.com]
-- If it exists, this script sends the photo of the sender to Growl from the address book. Otherwise, it sends the sender place holder image from Mail.app.
-- Original script found at [http://hunterford.me/growl-notifications-for-apple-mail-on-mac-os-x/]
-- This script uses a tip to summarise many messages by "Ryan" in the comments section at [http://hunterford.me/growl-notifications-for-apple-mail-on-mac-os-x/]
-- This script also used tips from [http://www.macosxtips.co.uk] for finding photos in the Address Book
-- This script arises from the lack of any Growl Support in Mac OS X Snow Leopard (10.6) or Lion (10.7)
-- 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 id "com.Growl.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
		set N to count items of theSelectedMessages
		if (N > 5) then
			set multipleDescription to "" & N & " new messages"
			tell application id "com.Growl.GrowlHelperApp"
				notify with name "New Email" title "You have " & N & " new messages." description " " application name "Mail"
			end tell
		else
			repeat with thisMessage in theSelectedMessages
				-- Process the current message
				
				-- Grab the subject and sender of the message
				set growlSender to my ExtractName(sender of thisMessage)
				try
					set growlPhoto to my getPhotoFromAddressBook(my ExtractEmailAddress(sender of thisMessage))
				on error
					set growlPhoto to read POSIX file "/Applications/Mail.app/Contents/Resources/SenderImagePlaceholder.png" as "TIFF"
				end try
				set growlSubject to subject of thisMessage
				set growlTitle to growlSender & return & growlSubject
				-- Use the first 100 characters of a message
				set growlDescription to (content of thisMessage)
				set growlLength to (length of growlDescription)
				
				if growlLength > 100 then
					set growlDescription to "" & (characters 1 through 100 of growlDescription) & " "
				end if
				
				-- Send a Notification
				tell application id "com.Growl.GrowlHelperApp"
					try
						notify with name "New Email" title growlTitle description growlDescription application name "Mail" image growlPhoto
					on error
						set growlPhoto to (read POSIX file "/Applications/Mail.app/Contents/Resources/SenderImagePlaceholder.png" as "TIFF")
						notify with name "New Email" title growlTitle description growlDescription application name "Mail" image growlPhoto
					end try
				end tell
			end repeat
		end if
	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_ as string
	end if
end ExtractName

-- *ExtractEmailAddress*
--
-- gathers the email address portion from the "From: " line
--
-- Source: robJ [http://forums.macosxhints.com/archive/index.php/t-19954.html]
to ExtractEmailAddress(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 email_ to second text item of sender_
			set text item delimiters to oldTIDs
		on error
			set text item delimiters to oldTIDs
		end try
		return email_ as string
	end if
end ExtractEmailAddress


to getPhotoFromAddressBook(sender_)
	set photo_ to read POSIX file "/Applications/Mail.app/Contents/Resources/SenderImagePlaceholder.png" as "TIFF"
	try
		tell application "Address Book"
			set photo_ to image of people whose value of emails contains sender_
		end tell
	on error
		set photo_ to read POSIX file "/Applications/Mail.app/Contents/Resources/SenderImagePlaceholder.png" as "TIFF"
	end try
	return photo_
end getPhotoFromAddressBook


[ Reply to This | # ]