Loading...

May 31, 2009

Let Grails use Snarl notifications in Windows

Snarl is notification system for Windows and is inspired by Growl. With Snarl applications can send out notifications and Snarl displays them with alpha-blended pop-up windows.

After reading Grails Growl-link notifications in Linux and Grails script notifications via Growl I got inspired to do the same thing for Snarl. First we must of course install Snarl. Next we must download Snarl_CMD.exe. With Snalr_CMD.exe we can display notifications from the command line. So now we create our _Events.grooyv script in <home directory>/.grails/scripts. For each event we want a notification of we invoke the Snarl_CMD.exe command with the correct parameters:

eventStatusFinal = { message ->
    snarlNotification('Final status', message)
}
eventStatusUpdate = { msg ->
    snarlNotification('Status', msg)
} 
eventCreatedFile = { fileName ->
    snarlNotification('Created file', fileName)
}
eventStatusError = { message ->
    snarlNotification('Error', message)
}
eventExiting = { code ->
    snarlNotification('Exit', "Return code $code")
}
eventCreatedArtefact = { type, file ->
    snarlNotification('Created artefct', "$type with name $file")
}
eventCompileStart = { kind ->
    snarlNotification('Compiling', "Compiling $kind")
}
eventCompileEnd = { kind ->
    snarlNotification('Compilation complete', "Compiled $kind")
}
eventPluginInstalled = { pluginName ->
    snarlNotification('Plugin installed', pluginName)
}
void snarlNotification(title, message) {
    def snarlCmd = [
        '<path to Snarl_CMD.exe>/Snarl_CMD.exe',
        'snShowMessage',
        '10', // Display notification for 10 seconds
        "$title", 
        "$message",
        '<GRAILS_HOME>/media/icons/grails - 32x32 icon.png' // Nice icon to show with notification
    ]
    snarlCmd.execute()
}

Now when we run for example grails run-app we get a Snarl notification: