libnotify with irssi over ssh
I’m an avid IRC user, sitting 24×7 usually connected to 5 server and 12 regular channels, and the only client I’m completely satisfied using is irssi. I run irssi on a remote server so I can easilly connect to it via ssh from wherever I am. I run it under screen so that I can re-attach to the same session from where ever I am and even have the same session shared across all my home PCs so i can look in and see whats happening whenever I want.
Recently I began playing with dbus alot, including libnotify. I found some irssi plugins for people running irssi locally to integrate with libnotify, but all the solutions by people for doing this remotely involved re-establishing ssh connections for each message and various other overheads that I was not comfortable with. The solution was obvious, to me - ssh needed dbus forwarding support. Well I don’t have the time nor experiece with the ssh code base to do it, a workaround was needed.
It didn’t take long for one to become apparent.
Nobody I know uses a relatively unheard of terminal capability known as terminal printing. This allows control characters sent to your terminal to turn on/off a locally connected printer. The content isn’t displayed by your terminal, but captured. Excellent, we could utilise this functionality for carrying a payload to the local machine, the connection is already there and the facility should be available in most terminal emulators (I’m a purist and use basic xterm which supports it).
What do I need?
- You need a terminal emulator that supports local printing. I’m using xterm 229
- libnotify and libnotify-bin, this includes the notify-send package
- a libnotify daemon (I’m using notification-daemon-xfce)
Obviously you’re already using irssi as an IRC/IM client, and you’re probably running it over ssh (and hopefully screen too if you are). But that is outside the scope of this article.
How is it done?
First thing we do is install the local handler script. This is the script that we configure xterm to pipe the content to be “printed” to.
Here is the script:
cat - | {
nt_icon=”gtk-dialog-info”
nt_time=5000
nt_head=”Notify”
nt_text=”Error Occured”
nt_type=”Message”
while read k v
do
case $k in
TYPE) nt_type=$v;;
ICON) nt_icon=$v;;
CONTENT) nt_text=$v;;
TIMEOUT) nt_time=$v;;
SUBJECT) nt_head=$v;;
esac
done
notify-send -i “$nt_icon” -c “$nt_type” -t $nt_time — “$nt_head” “$nt_text”
}
Grab it from here and put it somewhere sensible and make it executable.
The next thing that is needed is to configure XTerm to locally print using the script above. I use X resources for this. Infact I define a class in my Xresources called irssi and start xterm with a ‘-class irssi’ option for my IRCing.
If you don’t want a seperate class for irc, you can use the following lines. If you do want a class specific for your IRCing replace XTerm with the class name you like. The printer command should also point to wherever you put the script above.
*XTerm*printerCommand: /home/jared/bin/notifier
The last thing you need is the irssi plugin. I’ve uploaded it and attached it to this document, you need to download it and run it with /script load notify.pl inside irssi.
It is written by Luke Macken and Paul W Frields, i’ve adapted it deliver it’s payload to STDERR wrapped with ESC[5i (turn printer on) and ESC[4i (turn printer off)
Happy IRCing!
October 9th, 2007 at 2:25 am
Your solution requires the irssi running in some window (non-detached)? My ruby script uses irssi-proxy and is just a functional clone of the original script at UtSoft.org except that my script handles both latin and utf characters well :]. Granted, it needs one port open for each ircnet just like all other apps which use irssi proxy.
Let’s try also icecap sometimes. It evolves little by little and has a new promising client called Icegap ( http://icecap.irssi2.org/Clients/Icegap )
Greets!
October 9th, 2007 at 3:31 am
Yes It does require irssi running non-detached - but that was not an issue for me as i’m very rarely detached from my IRC sessions and If I am I probably don’t want to see notifications from them!
I had a play with the irssi-proxy setup for a while, and i was just never happy with the performance when compared to running irssi directly over ssh and under screen.
October 9th, 2007 at 3:47 am
It looks like the blog ate your script. There are unicode quotes and hyphens, but bash only seems to understand ASCII. If you copy/paste, be sure to fix all of the quotes and the — (should be two dashes).
October 9th, 2007 at 4:05 am
Thanks Eldon. I’ve uploaded a copy and linked to it now to make sure the non-digested version is available