Thinklight
From LinuxSwords Wiki
I am using my thinklight to notify me for new mails in my inbox and for my instant-messaging program gaim. I do this because I don not like the system default beep sounds and to be honest, I do not like notifying sounds at all. It disturbs me while I am listening music or I am watching a movie on my laptop
I have been asked by Alex to share the script to do this, so here it is
To set the script up on a linux-box we need two things
1. A script to address the thinklight device 2. The thinklight is owned by root, so we have to take care that any user is able to run it
1. The script
The thinklight device is located on /proc/acpi/ibm/light. This is an ubuntu-path, other distrution should have a similar path as well.
To turn the light on at the cmd-line we open up a shell and type:
echo on > /proc/acpi/ibm/light
if you are root. If not use sudo in front of the command. I will assume you are root for rest of this post.
To turn the light off simply type:
echo off > /proc/acpi/ibm/light
This is what we use in the script. Open a new file, lett us call it blink in a texteditor (gvim/vim/gedit/whatever) and type
#!/bin/bash
# script for blinking my thinklight
# needs to be run by root
# depends on /usr/bin/seq
if [ $# -ne 2 ] ; then
echo "usage: $0 <NbrOfBlinks> <Frequency>"
exit 1
fi
NBR_OF_BLINKS=$1
FREQUENCY=$2
THINKLIGHT=/proc/acpi/ibm/light
for i in `seq $NBR_OF_BLINKS`
do
echo on > $THINKLIGHT
sleep $FREQUENCY
echo off > $THINKLIGHT
sleep $FREQUENCY
done
Now make the script executable with
chmod 755 <blink>
and run it (as root) with some parameters
blink 3 0.1
This will blink 3 times with an interval of 0.1 seconds
2. Runnable as normal user
Now place the script named blink somewhere in your PATH, where your system will find it, like /usr/local/bin/ Now become root and edit the sudoers-file with visudo
Go to the last line and add
<username> ALL=(ALL)NOPASSWD:/usr/local/bin/blink
where <username> is your username. Save the file and exit.
You should now be able to run the script without a password with
sudo /usr/local/bin/blink 3 0.1
Finished! You can place last codesequence in a script and call it from whatever application you want. I am calling this script for my emails and instant messaging using 2 different frequencies. I do not use more because that is all I need and I do not want to turn my linux-box into a disco!!
