<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>blog@insidesystems.net: Growl, Mail.app and AppleScript</title>
    <link>http://blog.insidesystems.net/articles/2007/08/17/growl-mail-app-and-applescript</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Growl, Mail.app and AppleScript</title>
      <description>&lt;p&gt;I wanted a simple system that would notify me whenever I received an e-mail from somebody &amp;#8220;important&amp;#8221;, but not for every new message that hit my inbox.&lt;/p&gt;


	&lt;p&gt;I tried GrowlMail and Mail.Appetizer, but found them both unsatisfactory.  I finally decided that what I really wanted was a growl message to appear for messages from selected recipients.  Something with the name and the subject of the e-mail, like this:&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://blog.insidesystems.net/files/growl.png"&gt;&lt;/p&gt;


	&lt;p&gt;Fortunately, it turned out to be reasonably simple.&lt;/p&gt;&lt;p&gt;First, I opened up Address Book, and made sure that the important people were all listed in appropriate groups and correct e-mail addresses.&lt;/p&gt;


	&lt;p&gt;Having done that, I opened Mail.app, and added a rule:&lt;/p&gt;


&lt;blockquote&gt;
Description: Growl&lt;br/&gt;
&lt;br/&gt;
If any of the following conditions are met:&lt;br/&gt;
Sender is member of Group: Clients&lt;br/&gt;
Sender is member of Group: Family&lt;br/&gt;
Sender is member of Group: InsideSystems&lt;br/&gt;
&lt;br/&gt;
Perform the following actions:&lt;br/&gt;
Run AppleScript: ~/Library/Scripts/Applications/Mail/MailScript.scpt&lt;br/&gt;
&lt;/blockquote&gt;

but ho, you say, that script does not exist!  Never fear, then I loaded up Script Editor and created MailScript.scpt as follows:
&lt;pre&gt;
&lt;code&gt;
on perform_mail_action(info)

    tell application "Mail" 

        set selectedMessages to |SelectedMessages| of info
        set theRule to |Rule| of info

        repeat with eachMessage in selectedMessages
            set theSubject to subject of eachMessage
            set theSender to sender of eachMessage

            tell application "GrowlHelperApp" 

                set the allNotificationsList to ¬
                    {"New Mail"}

                set the enabledNotificationsList to ¬
                    {"New Mail"}

                register as application ¬
                    "MailScript" all notifications allNotificationsList ¬
                    default notifications enabledNotificationsList ¬
                    icon of application "Mail" 

                notify with name ¬
                    "New Mail" title ¬
                    "New Mail from " &amp;#38; theSender description ¬
                    theSubject application name "MailScript" 

            end tell

        end repeat
    end tell
end perform_mail_action
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Now, this was the first time I ever did anything in AppleScript, so it&amp;#8217;s quite possible there is a much better way to do all of this.  As it stands, I simply glued together some sample code from Growl and some sample code from &lt;a href="http://www.macosxhints.com/article.php?story=20030116071118239"&gt;this hint&lt;/a&gt; on the excellent &lt;a href="http://www.macosxhints.com"&gt;MacOSXHints.com&lt;/a&gt;, and it appears to work as desired.&lt;/p&gt;


	&lt;p&gt;Finally, I went into the growl prefpane, and set the priority and stickiness, so that these messages would stay on my screen even if I happened to be otherwise occupied when they came in.&lt;/p&gt;


	&lt;p&gt;Voila!  Nothing spectacularly complex, but it&amp;#8217;s a nice example of what I like about Apple.  Everything&amp;#8217;s easy to use out of the box, but when I dreamed up a random feature, I was able to implement it in a short period of time, despite having never even used their glue language before.&lt;/p&gt;


	&lt;p&gt;Hopefully somebody else would like this feature too!&lt;/p&gt;</description>
      <pubDate>Fri, 17 Aug 2007 14:55:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:74a15967-64c7-433a-a416-8f1c880d31be</guid>
      <author>Kevin Way</author>
      <link>http://blog.insidesystems.net/articles/2007/08/17/growl-mail-app-and-applescript</link>
      <category>E-Mail</category>
      <category>Off-Topic</category>
      <category>OS X</category>
    </item>
  </channel>
</rss>
