Notification script for Mail.app available

The Growl forums have moved to Google Groups, this forum is read only.
Mother
Harmless
Posts: 5
Joined: Wed Jun 04, 2008 5:52 am

Notification script for Mail.app available

Postby Mother » Sat Aug 29, 2009 9:31 pm

Hi all,

While I was using Entourage, I released a script to show Growl notifications on incoming emails, complete with subject line, from, body, stickies for high-importance emails, and now that Snow Leopard's Mail supports Exchange, I have dumped Office altogether, and switched to Mail + iWork. I've posted my new script here:

http://the.firehou.se/2009/08/29/growl- ... c-os-mail/

and here is a sample screenshot of the notifications you will get:

Image

It's all AppleScript, so no plugins to install. Suggestions, features, improvements & bug reports welcome - it's my second AppleScript so...

Cheers!

zxspectrum
Harmless
Posts: 5
Joined: Fri Aug 28, 2009 12:01 am

Re: Notification script for Mail.app available

Postby zxspectrum » Sat Aug 29, 2009 10:36 pm

Thanks :cool:

btw - is there a Growl-Stlye out there that is big enough to show an entire emal message??? Somthing like 'Mail.apetizer' use...Big priview and also customizable(if possible... :rolleyes:)


...

Mother
Harmless
Posts: 5
Joined: Wed Jun 04, 2008 5:52 am

Re: Notification script for Mail.app available

Postby Mother » Sat Aug 29, 2009 11:04 pm

You could try with one of the larger ones...but honestly, in some cases you really don't want a whole email on screen like that :D

My script strips double carriage returns to cut down the number of lines, and shows the first 80 characters of the email, you can edit it to show more characters as needed.

User avatar
rrm74001
Harmless
Posts: 23
Joined: Sat Aug 29, 2009 3:42 am
Location: Chandler, Arizona
Contact:

Re: Notification script for Mail.app available

Postby rrm74001 » Sun Aug 30, 2009 8:25 am


neoice
Harmless
Posts: 3
Joined: Sun Aug 30, 2009 11:02 am

Re: Notification script for Mail.app available

Postby neoice » Sun Aug 30, 2009 11:04 am

since this is the first time I've used Mail.app (using it for Exchange @ work), what does one gain by using GrowlMail over this simple script?

User avatar
rrm74001
Harmless
Posts: 23
Joined: Sat Aug 29, 2009 3:42 am
Location: Chandler, Arizona
Contact:

Re: Notification script for Mail.app available

Postby rrm74001 » Sun Aug 30, 2009 4:03 pm

neoice wrote:since this is the first time I've used Mail.app (using it for Exchange @ work), what does one gain by using GrowlMail over this simple script?


You just hove to go to alot more work to change the settings if you use this script. But with GrowlMail, you get a nice tab in Mail preference pane to change the settings:

Image

Plus it is more official. (GrowlMail is in the Extras folder when you download the Growl installer).

Both will work I guess. GrowlMail is just more flexible. But once growl v1.2 officially comes out, I do not see the point of this...

Mother
Harmless
Posts: 5
Joined: Wed Jun 04, 2008 5:52 am

Re: Notification script for Mail.app available

Postby Mother » Sun Aug 30, 2009 7:42 pm

I agree GrowlMail is be better than this (I'll be using it once it comes out of pre-beta), but it has not been working for quite a while (I believe it was actually pulled from the dmg at some point too?). Since there has not been any timeline given for fixes or updates to GrowlMail, I wrote the script when I switched to Mail from Entourage along with Snow Leopard, and had a need for Growl notifications.

aharpole
Harmless
Posts: 1
Joined: Sun Aug 30, 2009 10:27 pm

Re: Notification script for Mail.app available

Postby aharpole » Sun Aug 30, 2009 10:38 pm

FYI, if anyone's finding that Mail still gives them the error that GrowlMail was disabled, only to find it working, check your /Library/Mail folder for an empty GrowlMail bundle (assuming that you installed GrowlMail for your own user only). I had one and after deleting it Mail stopped giving me the error message.

User avatar
smajor
Latté
Posts: 84
Joined: Fri Dec 03, 2004 11:56 pm
Location: 127.0.0.1
Contact:

Re: Notification script for Mail.app available

Postby smajor » Sun Aug 30, 2009 11:14 pm

No offense to the Growl team, but that Mail plug-in has been sporadically wacky (for me) and always seems to break when someone in Cupertino just glances in its direction.

The last time it broke, someone here wrote a pretty decent AppleScript that I've salted to my taste and I haven't looked back since. I'm going to take a look at this one too. It was nice that I updated to 10.6 and just kept on a truckin' with my Mail alerts!

drstone
Harmless
Posts: 6
Joined: Sat Sep 27, 2008 3:25 pm

Re: Notification script for Mail.app available

Postby drstone » Wed Sep 02, 2009 4:21 pm

Using this script with exchange and mail, my growl notification is of the second to last email, not the most recent email?
Thoughts? Anyone?

Mother
Harmless
Posts: 5
Joined: Wed Jun 04, 2008 5:52 am

Re: Notification script for Mail.app available

Postby Mother » Wed Sep 02, 2009 8:31 pm

Does your most recent email become read at some point? My script parses all the emails passed to it by the rule, so if it's not shown, it can only be because:

a) the rule is not passing the first email to the script
b) the email breaks one of the filters in the script (eg. it has been already read, or it is marked as junk)

Hope this helps.

jdh
Harmless
Posts: 8
Joined: Sun Feb 25, 2007 11:41 pm

Re: Notification script for Mail.app available

Postby jdh » Wed Sep 02, 2009 8:39 pm

Thanks for this, it's a great little script. The main advantage in my case for a scripted Growl notification versus GrowlMail is that it allows me to be more selective about the notifications I receive. Since the script is triggered by a rule, it's trivial to have it do things like only notify for users that are in your address book, or only high-priority items, or even only messages from a specified group of individuals. I filter these conditions at the rule level to determine whether to trigger the script or not. As far as I can recall, GrowlMail doesn't provide any notification granularity beyond which mailboxes to notify from.

In fact, multiple iterations of the script could register themselves as different notifiers in Growl, or at least different notification types, which could then be used for further filtering with Growl itself to change notification styles or priorities. The big use I'm seeing here is to have the really urgent stuff use Prowl notifications, something that would quickly inundate me if I tried to turn Prowl on for general e-mail notifications otherwise.

I have made one small tweak to the script to look up the address book image for the sender, if it exists and display this in the growl notification in place of the generic normal/high-priority icons. If no address book record is found, or the user doesn't have an address book image, then the generic icons included in the package will be shown instead.

The modified script follows. You'll still need the original package from the site above for the README and the normal and high priority icons that are referenced in the script.

Code: Select all

(*

   Purpose: Displays Growl notifications when Mail receives new
            emails. Stickies urgent emails, others go away.
         
   Usage: Drag this script to /Library/Scripts or other suitable location. Place the
      two icon images in ~/Pictures. Create a rule in Mail that checks 'Every message' and runs the script from where you placed it.
         
   License: We don't need no stinkin' license!
   
   Created by Mike Puchol mike@the.firehou.se after dinner on the 29th of August, 2009, while on holiday with his family.
   Quick'n'dirty modifications added by Jesse David Hollington (jdh@hollington.ca) to look up sender image in OS X Address Book application.
   
*)

using terms from application "Mail"
   on perform mail action with messages theMessages for rule theRule
      tell application "Mail"
         repeat with eachMsg in theMessages
            -- Ignore if message read
            set readStatus to the read status of eachMsg
            if readStatus is true then
               return
            end if
            -- Ignore if message is spam
            set isSpam to the junk mail status of eachMsg
            if isSpam is true then
               return
            end if
            -- Not sticky unless urgent
            set msgStick to no
            -- Get message contents
            set msgSubj to get the subject of eachMsg
            -- Get the priority from the header
            try
               set priHeader to the header "X-Priority" of eachMsg
               set priHeaderStr to the content of priHeader as string
               -- Set priority
               if priHeaderStr contains "5" or priHeaderStr contains "4" or priHeaderStr contains "Lowest" then
                  set msgPri to -1
               else if priHeaderStr contains "3" or priHeaderStr contains "Normal" then
                  set msgPri to 0
               else if priHeaderStr contains "1" or priHeaderStr contains "2" or priHeaderStr contains "High" then
                  set msgPri to 2
               else
                  set msgPri to 0
               end if
            on error
               set msgPri to 0
            end try
            -- Body
            set msgText to the content of eachMsg
            -- Message length, grab only the first 80 characters
            set msgLen to the length of msgText
            if msgLen > 80 then
               set msgText to get text 1 through 80 of msgText
               set msgText to msgText & "..."
            end if
            -- Strip double carriage returns to make things fit nice
            set msgText to my findReplace(msgText, return & return, return)
            -- Get the from, either display name or email address
            set msgFrom to the sender of eachMsg
            -- Trim the from field if we have both name & email
            if msgFrom contains "<" then
               set msgAddress to get text ((offset of "<" in msgFrom) + 1) through ((offset of ">" in msgFrom) - 1) of msgFrom
               set msgFrom to get text 1 through ((offset of "<" in msgFrom) - 2) of msgFrom
            end if
            set senderpic to null
            tell application "Address Book"
               try
                  set thePerson to (the first person whose value of emails contains msgAddress)
                  set senderpic to image of thePerson
               end try
            end tell
            -- Set default icon
            set msgIcon to "~/Pictures/email_normal.png"
            -- And based on urgency, modify it
            if msgPri is 2 then
               set msgIcon to "~/Pictures/email_red.png"
               set msgStick to yes
            end if
            -- Set and enable Growl notifications
            set the allNotificationsList to {"New Email"}
            set the enabledNotificationsList to {"New Email"}
            
            -- Show the notification, only if priority is above -1
            if msgPri is greater than -1 then
               tell application "GrowlHelperApp"
                  -- Register ourselves
                  register as application "Mac Mail Growl Notifier" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Mail"
                  -- Notifiy Growl
                  if senderpic is not null then
                     notify with name "New Email" title (msgSubj) description ("From:" & msgFrom & return & "Message:" & msgText) application name "Mac Mail Growl Notifier" priority msgPri sticky msgStick image senderpic
                  else
                     notify with name "New Email" title (msgSubj) description ("From:" & msgFrom & return & "Message:" & msgText) application name "Mac Mail Growl Notifier" priority msgPri sticky msgStick image from location msgIcon
                  end if
               end tell
            end if
         end repeat
      end tell
      
   end perform mail action with messages
end using terms from

-- Simple find and replace routine
on findReplace(the_string, search_string, replace_string)
   tell (a reference to my text item delimiters)
      set {old_tid, contents} to {contents, search_string}
      set {the_string, contents} to {the_string's text items, replace_string}
      set {the_string, contents} to {the_string as Unicode text, old_tid}
   end tell
   return the_string
end findReplace


User avatar
boredzo
Cocoaforge Admin
Posts: 796
Joined: Mon Dec 06, 2004 7:49 am
Contact:

Re: Notification script for Mail.app available

Postby boredzo » Thu Sep 03, 2009 8:45 am

Mother wrote:I agree GrowlMail is be better than this (I'll be using it once it comes out of pre-beta), but it has not been working for quite a while …


Hence the pre-beta, which *is* working (so I hear—I haven't fired up Mail under Snow Leopard yet, but it's working for Rudy and others).

(I believe it was actually pulled from the dmg at some point too?).


No.

Since there has not been any timeline given for fixes or updates to GrowlMail…


It is already fixed. The beta is coming as soon as I get all the installer packages to a working state, which I am almost done doing.

We are not going to give you a date and time because that has no relation to when things are actually working. We put out releases when things are working, and no sooner and generally not much later.

User avatar
boredzo
Cocoaforge Admin
Posts: 796
Joined: Mon Dec 06, 2004 7:49 am
Contact:

Re: Notification script for Mail.app available

Postby boredzo » Thu Sep 03, 2009 8:50 am

smajor wrote:No offense to the Growl team, but that Mail plug-in has been sporadically wacky (for me) and always seems to break when someone in Cupertino just glances in its direction.


It used to be much more fragile, but has been quite robust for several versions now. If anything changes in a Mail internal API that we're using, GrowlMail simply disables itself so that it can cause no other problems. So far, that's never happened.

The problems we have had have been other changes we can do nothing about, such as Apple changing the BundleCompatibilityVersion number Mail requires. These changes are directed at, and affect, all Mail bundles.

The only solution to that, aside from using scripts instead of Mail bundles, is for Apple to start supporting the Mail-bundle interface beyond simply having it. This would include documenting it and putting out advance notice (e.g., in seeded versions of Mac OS X) of any breaking changes. Until they do that, all Mail bundles will lag behind Apple.

drstone
Harmless
Posts: 6
Joined: Sat Sep 27, 2008 3:25 pm

Re: Notification script for Mail.app available

Postby drstone » Sat Sep 05, 2009 6:06 pm

Mother wrote:Does your most recent email become read at some point? My script parses all the emails passed to it by the rule, so if it's not shown, it can only be because:

a) the rule is not passing the first email to the script
b) the email breaks one of the filters in the script (eg. it has been already read, or it is marked as junk)

Hope this helps.


It didn't help I'm afraid and I'm not sure why. I have the rule set to apply to all emails. I often have many unread emails and get new mail with some what alarming frequency ;(
I've stopped trying to figure it out and just installed the beta growl and growlmail which appears to be working as intended. Nice script for sure though.


Return to “Growl”

Who is online

Users browsing this forum: No registered users