Irssi OSD notifications

I wanted irssi to ping me using Ubuntu/Gnome’s on screen notification system, but didn’t want to dig into irssi’s code… what is one to do?

Cobble scripts together of course! Here’s how I got it done:

  1. Download this irssi plugin: fnotify.pl
    This script will update a text file  (~/.irssi/fnotify) with a new line every time you are pinged
  2. Put fnotify.pl in ~/.irssi/scripts
  3. autorun this script by executing:
    ln -s ~/.irssi/scripts/fnotify.pl ~/.irssi/scripts/autorun/fnotify.pl
  4. start irssi, and run:
    /hilight -nick {your_nick}
    /save
  5. When someone pings you, check the ~/.irssi/fnotify file for that ping, it should be there
  6. Download my script below (call it lastline_notify) and run it like this:
    ./lastline_notify ~/.irssi/fnotify & disown

[code lang=”python”]
#!/usr/bin/python
import os
import sys
import pyinotify
import pynotify

if (len(sys.argv) != 2):
print "usage: lastline_notify "
sys.exit(-1)
filename = sys.argv[1]

class PTmp(pyinotify.ProcessEvent):
def process_IN_MODIFY(self, event):
print "Create: %s " % os.path.join(event.path, event.name)

#get the last line in file
with open(filename) as myfile:
msg_text = (list(myfile)[-1])

msg = pynotify.Notification("Irssi Notification:", msg_text)
msg.show()

wm = pyinotify.WatchManager()
mask = pyinotify.IN_MODIFY
notifier = pyinotify.Notifier(wm, PTmp())
wdd = wm.add_watch(filename, mask, rec=True)
pynotify.init("Irssi")

while True:
try:
notifier.process_events()
if notifier.check_events():
notifier.read_events()
except KeyboardInterrupt:
notifier.stop()
break
[/code]

Viola! You now get a message in the upper right hand corner like if someone were to ping you on empathy. There might be a better way to do this, but it works for me! Both channel pings and queries should get a notification. This script runs as a daemon, so you shouldnt have to worry about it gobbling up CPU.

This entry was posted in Open Source, Random, Ubuntu. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *