Sending Growl Notifications from Ubuntu

Posted: June 29th, 2009 | Author: Remi | Filed under: OS X, Ubuntu | 8 Comments »

If you’re like me then you love being up to date on things happening on your network.  So when things were happening on my Ubuntu server I wanted to be alerted in some way.  I tried to use email but that was just impractical.  Then I came up with the idea to use growl.  If you don’t know, Growl is a messaging system for OS X that many applications use to notify the user with pleasant on screen notifications.  I remembered that growl would accept on notifications received over the network so I went out to the internet to find a way to send these notifications from Ubuntu.  I found a wonderful utility for doing it using python, which is a scripting language that comes pre-installed on Ubuntu. The name is pygNotify.  This would have been all fine and well and I would have had handy growl alerts form my server, but as it turned out there was very little documentation out there as to how to get this setup, and the included instructions are overly-simplified.  Therefore, I am writing this.

On the Ubuntu computer open the terminal, found in Applications > Accessories > Terminal.  First we’re going to create a folder to keep this growl stuff in.

mkdir ~/growl
cd ~/growl

of course you don’t have to keep it in your home directory
Next, lets download pygNotify

wget http://pygnotify.googlecode.com/files/pygNotify-0.1.tgz
tar xvfz pygNotify-0.1.tgz
mv pygNotify-0.1/pygNotify.py .
rm -r pygNotify-0.1

The next thing you need is get the python libraries from the growl SDK, that you can download from their website here http://growl.info/source.php Unfortunately the SDK is in a dmg so you’ll have to use a mac to extract it then copy it to the Ubuntu machine. You’ll need the folder Bindings/Python and also the script Bindings/Network/netgrowl.py. I will write the rest assuming you copied them into a folder called dmg in your home directory. Now we need to install the libraries. Cd into the directory you copied over from the dmg.

cd ~/dmg/Python
sudo python setup.py install

Now you need to move the netgrowl.py also from the dmg to the growl folder we created earlier

mv ~/dmg/netgrowl.py ~/growl

Then we should be done with the stuff from the dmg so we can clean up

rm -r ~/dmg

It should be all installed at this point. Now we need to enable receiving network notifications on the mac computers you want to receive the notifications from your ubuntu machine.

If you haven’t already, download and install growl from its website http://growl.info/ Once installed, go to System Preferences in the apple menu and click on Growl. Then click the network tab, then check “Listen for incoming notifications” and also check “Allow remote application registration” and set a password. Even if you don’t want a password, as far as I can tell you have to set one for it to work. Next you’ll need your computer’s ip address. Open Terminal.app found in /Applications/Utilities and type

ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2

The output should be your ip, write it down because we’ll use it in this next step.  Repeat for each mac.  Now back on your ubuntu machine we need to register your server as an application that can send notifications on your mac.

cd ~/growl
python pygNotify.py -n "Ubuntu Server" -p "password" -H your.macs.ip.address -r -m "register"

Please note that the second command is one line.  Replace password with the password you set earlier, and replace the part after -H with your mac ip address.  You’ll have to do this for every mac you setup to receive network notifications.

Note that the option after -n is the title of the application as it will appear to growl, and you can register multiple times with your mac if you use different names. By using different names for different sets of notifications it becomes possible to set customized settings for both on your mac. ie you could register “System Monitor” and maybe “Email Server” and have them have different message styles on the mac

Once the command runs, it should be registered on the mac and show up in the application list. A keychain confirmation may come up on the mac asking you if you want growlHelper to access the keychain. You should hit always allow, so this notification doesn’t come up every time.

Note: If when you run the command you get a “IndentationError: expected an indented block” when you try to run the script, my best guess is that its due to the formatting being messed up when you copied it to the server. If you find yourself unable to fix this just copy and paste the file from here: http://the.taoofmac.com/space/Projects/netgrowl and finally that worked for me.

Now to send a message

python pygNotify.py -n "Ubuntu Server" -t "test message" -p "password" -H your.macs.ip.address -m "hello world"

Again note that the command is one line.  The part after the -t option is the title of the alert, and the part after -m is the message. Also note if you want the alert to be sticky, meaning it stays on the screen, you can use the -s option.

And that’s, it hopefully. If you have problems with it registering or sending messages, be sure to check your firewall settings, to make sure growlHelper.app can access the internet, or that udp port 9887 is open I believe. Also you can try deleting the password set by growl in the keychain, and resetting it in the System Preferences Growl pane again. This can reset growl’s privileges to access the keychain, which may or may not be set to deny it access. The whole setup can be a finicky system at times, so good luck!