Mail と iChat を Growl

Mail

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

iChat

using terms from application "iChat"
on message received this_message from this_buddy for this_chat
(*EXAMPLE: this routine automatically sends a random response to messages from specified buddies
set this_name to the name of this_buddy
if the name of this_buddy is in {"Johnny Appleseed"} then
set canned_responses to {"Oh, I know!", "I was just thinking about that.", "Maybe tomorrow.", "Seems logical."}
set this_response to some item of the canned_responses
send this_response to this_chat
end if
*)
set this_name to the name of this_buddy
set this_image to the image of this_buddy
try
set this_subject to the subject of this_chat
if this_subject is missing value then error
on error
set this_subject to "NO SUBJECT"
end try
-- display Growl notification
tell application "Growl"
set allNotificationsList to {"New Message"}
set enableNotificationsList to {"New Message"}
register as application "iChat" all notifications allNotificationsList default notifications enableNotificationsList
if this_image is not missing value then
notify with name "New Message" title (this_name & " — " & this_subject) description this_message application name "iChat" image this_image callback URL "ichat:"
else
notify with name "New Message" title (this_name & " — " & this_subject) description this_message application name "iChat" callback URL "ichat:"
end if
end tell
end message received
end using terms from