Skip to content

Instantly share code, notes, and snippets.

@cockscomb
Created October 4, 2011 03:28
Show Gist options
  • Save cockscomb/1260839 to your computer and use it in GitHub Desktop.
Save cockscomb/1260839 to your computer and use it in GitHub Desktop.
Growl when new messages arrived.
using terms from application "Mail"
on perform mail action with messages these_messages for rule this_rule
tell application "Mail"
set the message_count to the count of these_messages
repeat with i from 1 to the message_count
set this_message to item i of these_messages
-- GET THE SENDER OF THIS MESSAGE
set this_sender to the sender of this_message
-- GET SUBJECT OF MESSAGE
try
set this_subject to (subject of this_message) as Unicode text
if this_subject is "" then error
on error
set this_subject to "NO SUBJECT"
end try
-- GET CONTENT OF MESSAGE
try
set this_content to (every character of content of this_message) as Unicode text
if this_content is in {"", "?"} then error
on error error_message
set this_content to "NO CONTENT"
end try
-- GET MESSAGE ID
try
set this_id to (message id of this_message) as Unicode text
if this_id is "" then error
on error error_message
set this_id to ""
end try
-- display Growl notification
tell application "Growl"
set allNotificationsList to {"New Message"}
set enableNotificationsList to {"New Message"}
register as application "Mail" all notifications allNotificationsList default notifications enableNotificationsList
notify with name "New Message" title (this_subject & " — " & this_sender) description this_content application name "Mail" callback URL ("message:%3C" & this_id & "%3E")
end tell
end repeat
end tell
end perform mail action with messages
end using terms from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment