Monday, February 01, 2010

Get notified of latest IRC message onscreen with notify-osd (code)

Problem
 When working away in the editor, you see that xChat, "your IRC client" has a new message of activity, and you can't bear to not check on it. The deeper problem lies in the fact that you are like one of Pavlov's dogs and respond to activity.

Solution
 A shell script + php script that reads your xchat channel log, and then sends to notify-osd (the onscreen popup display in Ubuntu et al) that latest message.


#### xchatNotify.sh ####

#!/bin/bash
while [ 1 ]; do
     ./main.php
     sleep 1m
done

#### main.php ####
#!/usr/bin/php
$update_file = DIRNAME(__FILE__).'/last_updated';
$log_file = '/home/peter/.xchat2/xchatlogs/FreeNode-#dspace.log';

$last_updated = filemtime($update_file);
$last_message = filemtime($log_file);
touch($update_file);


if($last_message > $last_updated) {
        $lines = file($log_file);
        echo 'Now: '.date('M d G:i:s');
        $message = $lines[count($lines)-1];
        $cmd = "notify-send \"$message\"";
        echo $cmd;
        system($cmd);
}

You need to have notify-osd and/or notify-osd installed on your system. My system is Ubuntu 9.10.

Room for Improvement
The shell script checks once a minute, and only displays the last message, so intermediate messages are not shown. But the purpose was just to show a message, which should give you enough context to either care or not care. Also, its only checking the one channel, and its not presented as a command line argument. Also, it would be nice to not alert you if xChat is currently the active window.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.