Adding notifications to finch

So, we use XMPP for our internal chat system at work, but I hate pidgin and empathy’s not much better. Naturally I searched for command line alternatives and the least offensive one I could find was finch, which admittedly uses libpurple on the backend, so it’s really pidgin, but at least it’s in a terminal now. Of course, I lost all my notifications of incoming messages, which isn’t cool, so I cooked up a simple script and call it instead of playing sound through finch. In finch’s “sounds” menu, simply change “Automatic” to “command”. In ubuntu, you’ll need two new packages:

sudo aptitude install libnotify-bin mplayer

And you’ll need this script, and to remember the path to it:

#!/bin/bash

latest_line=`find ~/.purple/logs/jabber/ -mtime -1 -printf "%T@ %Tx %TX %p\n" | sort -n -r | head | cut -d ' ' -f 2- | awk '{print $NF}' | head -1 | xargs tail -1 | sed -e 's#<[^>]*>##g'`
mplayer $1 >/dev/null 2>&1 &
notify-send "`echo $latest_line | cut -d ':' -f 3 | awk -F ')' '{print $2}'`" "`echo $latest_line | cut -d ':' -f 4-`"

3 thoughts on “Adding notifications to finch”

  1. Hey thanks a lot for this…very handy. The only thing was that for me the find line you posted didn’t quite work for me…I tweeked it a bit and got it working for me by doing this:

    latest_line=`find ~/.purple/logs -type f -mtime -1 -printf “%T@ %Tx %TX %p\n” | sort -n -r | head | cut -d ‘ ‘ -f 2- | awk ‘{print $NF}’| head -1|xargs tail -1| sed -e ‘s#]*>##g’`
    4 mplayer $1 >/dev/null 2>&1 &
    5 notify-send “`echo $latest_line | cut -d ‘:’ -f 3 | awk -F ‘)’ ‘{print $2}’`” “`echo $latest_line | cut -d ‘:’ -f 4-`”

    The find line is the only one that’s slightly different to what you posted above. Thanks again!

  2. hello,

    Thank you for putting this up here, quick question though. When I try to put ‘notify.sh’ in the “Sound Command” field in finch, the script is never hit, like it can’t reach it. notify.sh is in my path in ~/bin/notify.sh and has proper perms. I did notice that the is comment that says ‘(%s for filename)’. Do I need to put %s somewhere on that line for the filename ?

    Thank you
    Brandon

  3. Just wanted to thank you for this, it works perfectly as is under archlinux with xmonad. One addition I made was to include the line:

    echo -e "\a"

    This was so that a notification also set the window’s urgent hint, which I have xmonad configured to look for, and highlight the workspace that needs attention in xmobar. You may need to set your terminal up to pay attention to the alert character, I have terminator set to window list flash on terminal bell.

Leave a Reply