7

I know there is such a thing as a visual bell in Vim that makes the whole screen flash instead of beeping. Several terminal programs also have the same feature.

I'm looking for a similar type of visual bell that will flash all of my screens, on all of my virtual desktops, in X. I've only got headphones at work and my pc speaker is too quiet, so I need some other notification method that will definitely get my attention.

Does anyone know if it exists?

Neil
  • 2,589

11 Answers11

7

I don't of anything exactly like that, but you can use the command line tool notify-send to have pop-ups on the desktop. In Ubuntu the package is libnotify-bin. For example:

notify-send -u normal -t 10000 -i info 'hw' 'Hello world'
Kyle Brandt
  • 85,693
5

I had the same problem so I wrote a program for this:

https://github.com/rianhunter/xvisbell

To run:

$ git clone https://github.com/rianhunter/xvisbell.git
$ cd xvisbell
$ make
$ xset b on
$ xset b 100
$ ./xvisbell &
$ xkbbell # test

Hope that helps.

4

Depending on what you need, there is also xmessage—it's old, it's ugly, but it's included with X. It doesn't flash the screen, but it will pop up a message, and you can specify what buttons are on it (which one you press is returned in the exit status) if that's important.

2

You didn't specify GNOME or KDE, but KDE 4.2 has built-in support for this. If you look under System Settings > Accessibility, you can turn on the visual bell there. KDE also lets you customize actions for various system notifications that go beyond sounds. For example, you can show a popup, run a command, mark a taskbar entry, etc. This is under System Settings > System Notifications.

Rob H
  • 739
2

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.

Adam Katz
  • 1,082
2

I am surprised no one has even mentioned ansi escape characters. How about this (perhaps one of the cleaner solutions for a visual bell):

printf "\x1b[?5h"; sleep .1; printf "\x1b[?5l"

and done. :)


if you want to make a little method out of it, then just put the following in your bashrc/zshrc/whateverrc:

vflash(){
    printf "\x1b[?5h";
    sleep .1;
    printf "\x1b[?5l"
}

Now, your terminal will flash you when you put it at the end or long commands ... like sudo pacman -Syu; vflash; sudo apt-get update && sudo apt-get dist-upgrade; vflash; etc.

If you want it to keep flashing you (muweheheh):

flasher () {
    while :; do
        printf "\x1b[?5h";
        sleep 0.1;
        printf "\x1b[?5l";
        ## for bash
        read -s -n1 -t1 && break;
        ## for zsh
        # read -s -k1 -t1 && break;
    done;
}


NOTE1: This doesn't work in tmux or screen. :'(

NOTE2: This information was retrieved from Wikipedia: Ansi Escape Codes and modified. Read up! It's good stuff; I promise. :)

NOTE3: The ansi escape codes used are \x1b. In most linux-based OSs, you can use \e, but I always end up using \x1b because it works on OS X as well (even though I don't use OS X and never will).

Adaephon
  • 673
dylnmc
  • 121
2

Keep it simple - try this:
xrefresh -solid green
Feel free to repeat the command multiple times (perhaps even using different colors) to make your visual bell more impressive ... ;-)

F.M.
  • 121
1

You could use something like Zenity to show an alert dialog, or perhaps even a notification area item. You could also use dzen or xmsgd if you want something text-based. Note that none of these 'flash the screen' though.

eleven81
  • 417
1

Depending on the nature of the event and what desktop environment you are using, Specto might work for you.

dkaylor
  • 211
1

A tool called xcalib can invert video. Inverting twice achieves the visual bell effect. Here's the little snippet of code to do that.

for i in 1 2; do
  sleep 0.1
  xcalib -alter -invert
done
utah
  • 11
0
B=$(backlight); backlight 0 ; sleep 0.5 ; backlight 100 ; sleep 0.5 ; backlight 0 ; sleep 0.5 ; backlight $B

backlight is a POSIX-compliant (pure bourne shell) script that allows you to get and set the brightness of the screen via /sys/backlight if supported by your system. It also helps you set the permissions allowing a specific group to set the brightness and remeber it over reboots.

backlight is available here: https://github.com/fraxflax/backlight