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?

11 Answers 11

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'
3
  • Since this works in any window manager, I'd say it's the best answer for now.
    – Neil
    Jun 4, 2009 at 16:55
  • This is a pop-up and not a visual bell. There are at least two answers to the question that actually provide visual bell functionality.
    – Adam Katz
    Apr 30, 2015 at 0:35
  • @ Neil Best non-answer I may say. Actually, only correct and full answer is from @Rian Hunter
    – catpnosis
    Jun 5, 2015 at 12:42
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.

1
  • That's cool. I hope there's a Gnome equivalent.
    – Neil
    Jun 4, 2009 at 16:55
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.

3
  • This is like half of answer. OP asks how to make beep sound (because he can not hear it) visual. You only answering how to flash backlights, but not how to attach that functionality to beep sound.
    – catpnosis
    Jun 5, 2015 at 12:38
  • @catpnosis: That's not how I read the question. Anyway, adding a sound would be trivial, just add mplayer "${2:-/path/to/default/sound}" (or use your audio player of choice in place of mplayer). This will let you specify the sound with the second argument or else default to /path/to/default/sound. EDIT: Ah, perhaps you're referring to installing this as the bell itself. In that case, see Rian Hunter's answer. This answer only tells you how to change an application's specific sound command.
    – Adam Katz
    Jun 5, 2015 at 16:22
  • Yes, he asks how to replace beep (which is sound) with visual flash. Not how to just flash screen, show popup message, or play a custom sound. But how to make system beep 'visual'. And yes, only one (Rian Hunter's) answer is correct from six given.
    – catpnosis
    Jun 6, 2015 at 10:24
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).

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 ... ;-)

3
  • Judging from the man page it sounds like that command is supposed to work. However I just tested it on Ubuntu 14.04, and it did nothing.
    – kasperd
    Jan 1, 2017 at 2:27
  • Hi kasperd. I have used this trick for decades on many Unix-like systems running X11 (Solaris, HP-UX,..) and it also works as expected on my two current Linux boxes (Xubuntu 16.04.1/x86_64 + Raspbian jessie/armv7l). I suspect you have an issue with your video driver. Does xrefresh work for you at all, does it repaint all GUI apps, do you see any effect on your screen (does it shortly flash)? Does xrefresh -black work (i.e. flashing in black for a fraction of a moment)? Are you accessing a headless system via VNC or Xrdp (both might ignore/strip the few video frames xrefresh generates)?
    – F.M.
    Jan 1, 2017 at 23:06
  • I tested it on my Debian Buster installation, with NVIDIA graphics drivers, doesn't work, no visual effect.
    – Frank Buss
    Oct 18, 2020 at 20:11
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.

1

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

1
  • Note to modern readers: Specto was announced as obsolete in 2013 and is now without a maintainer. I'm also not sure it supported a visual bell, as it seems to be a notification system for ~GNOME pre-3.6
    – Adam Katz
    Apr 30, 2015 at 0:40
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
1
  • This is the only easy way that worked for me, thanks. The problem is that it inverts all screens, because the "-s" switch doesn't work. I compiled and installed the xrandr-invert-colors program, as explained here: askubuntu.com/questions/1087718/… Now I can just call "xrandr-invert-colors -s 1" to just change it for screen 1, or 0 for screen 0. Very useful when streaming one screen on Twitch, and you want to be notified when someone is chatting (for low volume chat channels like my channel).
    – Frank Buss
    Oct 18, 2020 at 20:21
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .