Sonntag, 14. Januar 2007

thl's irssi notification script [UPDATED]

A while ago Luke Macken wrote an irssi notification script and blogged about it. I really liked the idea having pop-ups (using libnotify) on all of my desktops when somebody mentions my name in on of the channels. But well, the script had one big problem for me: It requires irssi to run on the local machine.

But I run irssi within screen on another machine in another network – I just ssh into that machine normally and resume the irssi-session with "screen -R". Thus I could not use lmacken's script :-(

I looked a bit more into that some time ago and came up with another solution: fnotify. Download it and put it as fnotify.pl in .irssi/scripts/ and load it in irssi with
/load perl
/script load fnotify

Is somebody chats to you directly (query) or mentions your nick somewhere in one of the channels it will put something like
#fedora-devel foo> ping thl

into ~/.irssi/fnotify . I can read that file from the client via ssh now and fire up notify-send locally. I use this startup script do realize that:
# yes, we need a way to flush the file on disconnect; i don't know one
# yes, that's flush is not atomic (but good enough for me)
ssh remote.system.somewhere "tail -n 10 .irssi/fnotify ; : > .irssi/fnotify ; tail -f .irssi/fnotify " | sed -u 's/[<@&]//g' | while read heading message do notify-send -i gtk-dialog-info -t 300000 -- "${heading}" "${message}"; done # the sed -u 's/[<@&]//g' is needed as those characters might confuse notify-send (FIXME: is that a bug or a feature?)

This results is nice pop-ups in the bottom right corner of my desktop:

Site note: Yes, there are probably 1000 other ways to realize something like that. The above stuff is far from perfect, but it suits my needs.

10 Kommentare:

quaid hat gesagt…

In the first set of commands, you dropped the 'f' from 'fnotify'. It should read:

/load perl
/script load fnotify

Otherwise, I don't have it working yet. That is, fnotify.pl is putting stuff in ~/.irssi/fnotify just fine, but I haven't been able to get anything meaningful via the local script yet. Running it generates a, "No summary specified." output.

Thorsten Leemhuis hat gesagt…

> In the first set of commands, you
> dropped the 'f' from 'fnotify'.

Fixed

> Running it generates a, "No summary
> specified." output.

Seems notify-send isn't called properly. Put a "echo" in fromt of it to debug.

Paul W. Frields hat gesagt…

Hi Thorsten,

I did a little update of Luke's script as well. Mine doesn't require any tailing of files or other hacks; it calls notify-send and only assumes you have X forwarding on. See http://code.google.com/p/irssi-libnotify/ for the download.

Anonym hat gesagt…

Thanks for your script. Just a little side-note to your sed-hack: The Desktop Notification Specs allow some markup to be included in the message, so a cleaner solution would be: sed -u "s/</\&lt;/g;s/>/\&gt;/g;"
I actually expanded it a little so I can now click URLs and the nicks are printed in bold.

Romain Chossart hat gesagt…

It is missing a ";" just after before the "do" of "while..."
Works like a charm, thanks :)

Anonym hat gesagt…

good post

Anonym hat gesagt…

Ive bee working a bit with this, using the tail method as my server is headless (no X)...

Im using xdotool to check if my irssi window is active, the notify happens if not. Also playing a sound.

while read heading message;
do
if [ ! `xdotool search --name zzzAmazon` = `xdotool getactivewindow` ]
then
mplayer /usr/share/sounds/gnome/default/alerts/glass.ogg &
zenity --info --title="${heading}" --text="${message}"
fi
done

Anonym hat gesagt…

Hi this post is very old, but perhaps it would help someone:
there are two problems with bash script mentioned above. 1. when the script is interrupted, there are processes (tail -f) staying alive on the remote host. And 2. flushing the fnotify file on exit. This can be done with signal traping. Here's the updated script:

ssh -t user@remotehost "trap 'echo Exit requested.; :> ~/.irssi/fnotify; exit 0' SIGINT SIGTERM SIGKILL; tail -f .irssi/fnotify;" | sed -u 's/[<@&]//g' | while read heading message; do notify-send -i gtk-dialog-info -t 9000 -- "${heading}" "${message}"; done

Guyzmo hat gesagt…

Hello, FYI, I wrote in 2010 (and updated lately to version 1.0) a notification over ssh hack you can find over here: Notossh or on my github.

HTH,

--
guyzmo

James hat gesagt…

Hi there, I wrote something similar, and it flushes old messages on disconnect.

Have a look:

https://ttboj.wordpress.com/2013/10/18/desktop-notifications-for-irssi-in-screen-through-ssh-in-gnome-terminal/

HTH,
James