Yes, this is possible!
The following is an implementation that dims your monitor's LCD backlight and then brings it back to where it was.
Step one: find a way to reliably alter your backlight [1][2]. I'll use the simplest one here but ymmv.
There are kernel(?)-level controls in /sys/class/backlight. The exact subdirectory name will vary based on your setup. I'm using this method in this example, but if you find another command that works, you can skip step two and alter the script in step three to have the get_brightness
and set_brightness
functions use your chosen method.
This will give you your current brightness level
cat /sys/class/backlight/intel_backlight/brightness
Now try changing it:
export BRIGHTNESS=/sys/class/backlight/intel_backlight/brightness
echo 50 |sudo tee $BRIGHTNESS; sleep 1; echo 80 |sudo tee $BRIGHTNESS
This should make your screen darker for one second and then bring it to level 80 (use the value you got earlier or else your display may be too dark). I've bundled them into the same command so you don't get stuck with a screen that is too dark. In this test, we're acting as root. We'll get access for your own account next. (Stop here if it doesn't work!)
Step two: get access for your own account:
sudo chmod g+w /sys/class/backlight/intel_backlight/brightness
sudo chgrp video /sys/class/backlight/intel_backlight/brightness
sudo usermod -a -G video my_username
(Note, this might not survive rebooting. I'll come back and revise this if that's the case, but I only reboot ~quarterly, so bear with me.)
Step three: write a script like the following:
#!/bin/sh
help() { cat <</help
Blink/flash the whole X display (on one LCD monitor)
Usage: visual-bell [BLINK_COUNT]
0.2+20140327 Copyright (c) 2010+ by Adam Katz <www.khopis.com/scripts>, LGPL 2+
/help
}
SLEEP_TIME=0.03
BRIGHTNESS=/sys/class/backlight/intel_backlight/brightness
get_brightness() {
cat $BRIGHTNESS
}
set_brightness() {
echo $1 > $BRIGHTNESS
}
COUNT=${1:-1} # read count from first argument (default to one blink)
# if the argument wasn't a number greater than zero, show help and exit
if ! [ "$COUNT" -gt 0 ] 2>/dev/null; then
help
exit 1
fi
LEVEL=`get_brightness`
while [ $COUNT -gt 0 ]; do
set_brightness 0 # blacken the screen
sleep $SLEEP_TIME
set_brightness $LEVEL # revert the screen to previous brightness
sleep $SLEEP_TIME
COUNT=$((COUNT-1)) # decrement counter
done
You should be good to go. Save that as /usr/local/bin/visual-bell
and make it executable (chmod +x visual-bell
), then you can run it. This script will blink the given number of times (defaults to one), so you can run visual-bell 3
to blink three times.
You can theoretically blink multiple monitors if you use /sys/class/backlight/*/brightness
but beware that different monitors may have different brightness scales. My Dell LCD (connected via a DisplayPort-VGA adapter) does not work here, though my laptop display does.
Further steps: Install as the "sound command" in programs like pidgin. I do not know how to do this in terminal emulators.