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


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: 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 | # ]