CenterIM notify

This described how to add a notify feature for my prefered IM-client Centerim under the following scenario: access a screen session running on a central server from different clients getting notification on the client when an event happens.

It's inspired by this entry about connecting irssi to libnotify.

The clever part of the idea is the exploit of the terminal print capabilities which can be turned on and off by control characters. When it's turned on the terminal captures text and sends it to an external program. By turning on this functionality one can make use of CenterIM external actions and a few scripts to turn on notification.

xResources

To do this first we need to make the terminal aware of what to do when print is activated. This is done by adding the following to your Xresources:

xterm*printerAutoClose: true
xterm*printerCommand: /home/nemo/projects/centerim/notifier/notifier

The first line tells the terminal to close the pipe to the program when print is turned off. The second line is the path the program to where the text is piped. If you dont wan't to turn the print functionality on for all your xterms its possible to restrict the options by changing xterm*… to <anotherID>*…. and starting the xterm with -class <anotherID>. For more information see xterm(1).

You can add these lines to your local Xresources file (located in '~/.Xresources'). Run

xrdb -merge ~/.Xresources

to update your resources. Get a list of your current settings by calling 'xrdb -query | grep “xterm”'.

Server side

Next we need Centerim to notify the xterm by switching on and off printing when an event occurs. This can be done by using the feature called External actions (see chapter 9.3 of the Centerim README). An external action is a mapping from an event to an external script. So what you do is to add an entry to the external configuration file in you centerim path (ie. ~/.centerim/external or ~./centericq/external). It will look something like:

%action
event           msg
proto           all
status          all
options         stdin

%exec
msg=`cat`
$HOME/.centerim/scripts/notify.pl $msg

The script is called on 'msg' events on all protocols no matter you IM status, sending the message to stdin. The script are placed in the 'script' folder of your CenterIM directory.

The script:

#!/usr/bin/perl
 
my $str = "\033[5i\n";
$str .= "FROM " . $ENV{'CONTACT_NICK'} . "\n";
$str .= "MSG ";
foreach $num (0 .. $#ARGV) {
     $str .= "$ARGV[$num] ";
}
$str .= "\n";
$str .= "\033[4i";
 
print STDERR $str;

It first sends the character to turn on the print functionality, then sends a line containing the nickname of the sender and then sends a line containing the message. Here it prints to stderr to avoid interfering with CenterIM (but as stdout is not defined in the options-field of the configuration of the external action, this should not? be a problem). And before terminating it turns off the print switch.

Client side script

The final part is the script which notifies.

#!/bin/bash
 
From=""
msg=""
while read t l
do
  case $t in
    FROM) from=$l;;
    MSG) msg=$l;;
  esac
done
if [ -n "$from" -a -n "$msg" ]
then
  notify-send -t 5000 "$from" "$msg"
fi

It receives the input and scans it for the lines containing the sender and the message. If such two lines where found they are used to call the notify daemon (with timeout of the message set to 5 seconds).

Thats it! And remember to make the scripts executable by 'chmod +x <script>'.

 
cimnotify/centerim_notifier.txt · Last modified: 2009/03/09 15:23 by jsc
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki