AppleScript C Perl Shell Xcode Other

Growl notification for Apple Mail under Snow Leopard

Post Reply
coding / applescript     Views: 10972Prev .. Next
Growl notification for Apple Mail under Snow LeopardPosted: Tuesday, June 22, 2010 [21:17:49] - 1
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
If you want to have nice floating notifications on important email messages received by Mail program under Show leopard - first download Growl at:
http://growl.info
and run the installer.
Make sure Mail is Enabled in "System Preferences" under "Growl" pane:
Post 77259469 Image 1
Then create an AppleScript:
View 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

Compile script (press "Apple+K") and run it first to register with Growl by pressing "Apple+R".
Save script in: /Library/Scripts/Mail Scripts/Rule Actions/Growl.scpt
(you could save it anywhere else but, to keep tabs on a code this location makes better sense).

Then you'll need to setup your Mail rules. In Mail program click "Apple+," (that's comma) and select "Rules" pane.
Post 77259469 Image 2
and click on "Add Rule".
add as many options as you need to match the message you want to be notified about:
Post 77259469 Image 3
Click "OK". You will be presented with message asking you to apply rule to already received messages - click "Don't Apply"
Post 77259469 Image 4
close Mail Preferences.
You're done! From now-on when you receive an important message - a small floating message will appear on your Mac screen letting you know of a new message.There's no place like ~
coding / applescriptPrev .. Next
 
Post Reply
Home - Coding: AppleScript C Perl Shell Xcode Other
Our Telegram Group