Growl Alerts for Gmail Messages from Address Book

Ever since I stopped using Mail, I've been looking for a replacement Applescript that would announce new messages using Growl if they came from people in my Address Book, or were replies to my messages. If Gmail allowed you to label messages as 'known' if they came from people in your Contacts, this would be easy in combination with a Selective Notifications setting.

I just noticed (though it's been there for years) that Google Notifier can be customised with Applescript plugins, so here's a script that shows a notification if a new message arrives from someone in your Address Book (save it in ~/Library/Application Support/Google Notifier - you might need to create that folder). I can't find a way to search Address Book by email address (have to use Spotlight, maybe), so the email sender's full name and email address both have to match the entry in your address book for it to work.

on NewMessagesReceived(messages, fullCount)
	set notificationsList to {"New Gmail message"}
	tell application "GrowlHelperApp" to register as application "Google Notifier" all notifications notificationsList default notifications notificationsList icon of application "Google Notifier"
	
	repeat with m in messages
		tell application "Address Book"
			repeat with p in (every person whose name = (|authorName| of m))
				if (value of every email of p) contains (|authorEmail| of m) then
					tell application "GrowlHelperApp" to notify with name "New Gmail message" title (|title| of m) description (summary of m) application name "Google Notifier" with sticky
					exit repeat
				end if
			end repeat
		end tell
	end repeat
end NewMessagesReceived