Security

Fun tricks with Growl and GeekTool

Finding one app that does exactly what you want is one thing, but combining two apps to do something really specific to your needs is really cool. Find out what you can do with Growl and GeekTool on a Mac.

Finding one app that does exactly what you want is one thing, but combining two apps to do something really specific to your needs is really cool. Find out what you can do with Growl and GeekTool on a Mac.

---------------------------------------------------------------------------------------

I am a huge fan of the free Growl application, which allows other applications to tell you what's happening with them. For instance, Growl can alert you when new files are downloaded from Dropbox, when a track changes in iTunes, and so forth. I'm also a big fan of GeekTool, which allows you to display various bits of information on your desktop, like uptime information or the weather, or anything else you like that can be run from a script or contained in a text file.

Combining the two is even more interesting, and there are tons of possibilities here. I'm going to describe a unique method of using the two together to accomplish something I've needed myself, in the hopes that it might get the creative juices flowing for how GeekTool and Growl can work together for you.

For security reasons, I have a VMware Fusion virtual machine running Fedora, which connects to a VPN. The VPN is not accessible outside of the virtual machine (the primary reason being that I used to run two physical systems: one running Fedora, the other OS X, because each belonged to a different kerberos realm). In the interest of saving power, the Fedora system turned into a virtual machine on the Mac. With this, I can ssh into the virtual machine from the host, where mutt and irssi run. The only GUI application used is Firefox, which I can get on the Mac desktop by starting X11.app and using ssh -X to the virtual machine, and starting Firefox from the command-line. The benefits to this are that Firefox gets the kerberos credentials and routing to the VPN from within the virtual machine, and I get Firefox as an application on the Mac desktop.

Unfortunately, by having the ssh session to the virtual machine as one of many tabs in Terminal, it is easy to miss any highlights in irssi, so someone could be trying to get my attention and I may not realize it for quite a while. The only real way to keep an eye on IRC was to have a separate Terminal just for that ssh session and keep it visible, so that I would notice if anyone tried to get my attention. However, this was a less than ideal solution.

Finding a script called fnotify.pl for irssi, I was able to make irssi write highlights to a file (~/.irssi/fnotify). Because I have the host and virtual machine share a directory via Fusion's shared folders, I created a symlink to a file on the shared drive so it was accessible on the Mac:

$ touch /mnt/hgfs/Shared/fnotify
$ ln -s /mnt/hgfs/Shared/fnotify ~/.irssi/fnotify

Now, whenever fnotify writes a highlight, it writes it to a file accessible on the Mac, which we can then use a script to manipulate. This is my ~/bin/gt-irssi script:

#!/bin/sh
mv -f ~/.fnotify ~/.fnotify.old
cp -f ~/Documents/Shared/fnotify ~/.fnotify
tail ~/.fnotify
# growl notification; the rest is displayed on the screen
diff -uN ~/.fnotify.old ~/.fnotify | grep '^+' | grep -v '^+++' | cut -d '+' -f 2- | \
while read dow month day time year nick message; do \
    /usr/local/bin/growlnotify -s -a Linkinus.app -m "${message}" -t "${nick} @ ${time}" -n irssi ;\
done

What this script does is copy the fnotify file to ~/.fnotify after renaming the existing ~/.fnotify file to ~/.fnotify.old. This is done so that I can use diff to tell me if there are any new highlights. It also prints out the last 10 lines of the file (using tail); this is what will get printed to the desktop via GeekTool. It reads in the output of diff, so that any new additions to the file get sent to growlnotify, a command-line tool that interfaces with Growl: here it sets the message to the actual text from IRC, and sets the title of the notification to "nick @ time", so I can see when the notify came, and by whom. I use the -a option to have the Growl notification show the Linkinus IRC application's icon, and use -s to make it sticky so that it will remain on the desktop until I click it away. The -n option is used to give it a unique name so that in the Growl Preferences I can change how the notifications look and where they are placed.

The final step is to fire up GeekTool and create a new shell item that runs the ~/bin/gt-irssi script every five minutes. So every five minutes GeekTool's display of the last 10 IRC highlights refreshes, and if there are any changes, growlnotify is called to display the new highlights on the desktop.

In this instance, GeekTool both displays information on the desktop and is used as a bit of a cron replacement, in that it will run the script automatically. With it, I can work without worrying about keeping an eye on one Terminal window, knowing that within five minutes, anyone trying to get my attention, or talking about something I am interested in, will have my attention via Growl's notifications.

Obviously this solution is quite unique and not everyone will require it, but my hope is that it got you thinking about other creative things you can do with GeekTool and Growl. Because GeekTool runs command-line programs and scripts, there really is no limit to what can be done with it. It can be used to monitor the local system state and alert on specific changes, or monitor remote systems via ssh commands and display pertinent output and alerts. The flexibility of this kind of application "gluing" makes it all the more powerful, and fun to mess around with.

About

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

0 comments