September 30, 2012

Sending messages to Growl from the command line

At home I am using a self-built mediacenter that also acts as a NAS and torrent box. The torrent client on it is transmission. Things are running smoothly and Transmission’s option to run a script after a torrent has finished downloading is very nice. It is currently used to log what happened to the latest torrent and unpack any archive it might find in it.

But one things was missing: notifications. I would like to know when a torrent is added or has finished. Unfortunately Transmission doesn’t support any action on adding but the “run script after” function can be used for notifications. But what kind of notifications should I send? I don’t want to use email for this, it feels clumsy and a bit overkill. But I do run Growl on my laptop and I know it can listen for incoming messages using the GNTP protocol.

So I started digging around, found that there is a GNTP command line client that can be compiled on OS X and Linux. For some reason I had issues compiling it on media center and that is when I found help from my good old friend Perl and its comprehensive CPAN module library where of course I could find a GNTP module. Using it is not that straightforward though so I quickly hacked together a Perl script that makes it easier to send a message from the command line or from any app or script.

I have made the script public on Github in a repo that also contains my unpack script in case anyone finds it useful. You can find the repo here.