James Williams
LinkedInMastodonGithub

Adding Growl notifications to Griffon applications

Tags: Griffon

One of the things I am reminded of when WWDC rolls around, other than Silicon Valley's crush on all things Apple, is the extra little bit of polish in OS X applications. Part of that polish is the Growl notification system and adding Growl notifications is one way to make your applications feel more native. It exists in some shape or form on all three major platforms. I'll be demonstrating how to integrate Growl in a Mac or Linux Griffon application, Windows will have to wait until I have the time to unify targeting the three in a plugin.

Firstly, Make sure you have growlnotify(OS X) or libnotify-bin(Ubuntu) installed.

Next, add the following script to your src directory of your app:

public class Notifier {
    final static String OS_NAME = System.getProperty("os.name")

    static void sendNotification(title, msg, icon) {
        try{
        if (OS_NAME.equals("Linux")) {
            def cmd = "notify-send ${title} ${message} -i ${icon}"
            cmd.execute()
        } else if (OS_NAME.equals("OSX")) {
            def cmd = "growlnotify -n ${title} -I ${icon} -m ${message}"
            cmd.execute()
        }
        } catch (IOException ex) {
            // very possible that the required package (libnotify-bin on Linux or growlnotify on OS X) is not installed
        }
    }
}

Now you can call your Notifier from your controller just like any other class. Calling the command-line versions directly is a bit messy but it is probably what the Java libs are doing anyways.

In a plugin, possibly a hook could be added to installer scripts to ask if the user would like to receive growl-like notifications and then install the requisite packages.

What else do you think a growl plugin should do? Comment on this post or better yet on user@griffon.codehaus.org

For those that are curious, there is Growl for Windows.

Thanks to Colin Harrington and Marc Palmer for the inspiration.