One of my favourite plugins for pidgin is pidgin-blinklight, which blinks my ThinkPad's ThinkLight upon the arrival of new messages. Pretty useful as it is not as annoying (especially for others around you) as playing weird sounds. Unfortunately such a plugin is not available for other messengers like psi - but you're able to specify your own sound player. So I came up with the following script, which is my default sound player in psi now.

#!/bin/bash

IBMLIGHT="/proc/acpi/ibm/light"

function light_is_on() {
    [ "on" = "`grep status ${IBMLIGHT} | awk '{print $2}'`" ]
    return $?
}

function light_off() {
    echo off > ${IBMLIGHT}
}

function light_on() {
    echo on > ${IBMLIGHT}
}

if light_is_on; then
    light_off
    sleep 0.2
    light_on
    sleep 0.1
    light_off
    sleep 0.2
    light_on
else
    light_on
    sleep 0.2
    light_off
fi

Hint: In case you want a blinking light and sound, just add something like exec /usr/bin/play $@ at the end of the script.

comment 1

Cool script, but a few nitpicks :)

  • Since status is the first line, you can read it without fork/exec-ing two processes:

    read status on_off < /proc/acpi/ibm/light

    or if you want to play it more defensively in case the lines are swapped:

    awk '/^status:/ {print $2}' < /proc/acpi/ibm/light

    No need to use grep with awk :)

  • Also, the return $? isn't necessary, it's implied

  • Then get rid of "function", it's just a bash-only decorator that breaks compatibility with other shells. Then you can run with dash and save even more cycles :)

Comment by Anonymous Thu 23 Jul 2009 04:40:18 AM CEST