8

Is there a way to flash the screen from the command line? I am looking for the same effect that Accessibility does for "Flash the screen when an alert sound occurs", but I don't want it for every alert.

4 Answers 4

6

As far as I know, you can't replicate this alert without enabling that option. If you do enable that option, you can cause a flash from Terminal using:

osascript -e "beep"

However, if you don't want to enable that option, you can use invert colours. Using the invert colours Accessibility option twice causes the screen to flash, therefore pressing the keyboard shortcut ⌃⌥⌘8 twice will cause a flash:

#!/usr/bin/osascript
tell application "System Events" to repeat 2 times
key code 28 using {command down, control down, option down}
delay 0
end repeat
2
  • I wonder if the script can check to see if the current setting is to beep or flash and then change the setting if needed, call the "beep" and then change the setting back (only if it made a change?).
    – bmike
    Commented Jul 3, 2017 at 20:21
  • Looks like this other answer found an even better implementation of my code comment above. apple.stackexchange.com/a/288696/5472
    – bmike
    Commented Jul 3, 2017 at 20:22
3

It doesn't flash the whole screen (unless you have terminal set to full screen) but if you go to Preferences > Settings > Advanced and select "Visual Bell" you can then type:

echo ^G

(The keystrokes to get the correct characters are: echo control + v control + g because the control character has to be quoted)

to flash the terminal window.

2
  • 1
    Whilst this works, the effect is very subtle on my default Terminal profile.
    – grg
    Commented Apr 11, 2014 at 16:34
  • Another option is printf '\a'.
    – zneak
    Commented Jul 3, 2017 at 20:19
2

This works for me in Sierra via applescript:

tell application "System Preferences"
    run
    reveal anchor "Hearing" of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events" to tell process "System Preferences" to click button "Test Screen Flash" of window "Accessibility" of application process "System Preferences" of application "System Events"
3
  • Very elegant solution. I had suggested on another answer to actually change the settings (if needed), call a beep and change the settings back. this seems much better to get one off flashes.
    – bmike
    Commented Jul 3, 2017 at 20:23
  • @bmike The trouble with this is it takes a number of seconds to execute especially if the app isn’t open first, no doubt it’s elegant apart from that
    – grg
    Commented Jul 3, 2017 at 20:29
  • Indeed @grgarside - for speed here, you'd likely need to use python and the objective-c bindings to script up what is in essence a small cocoa app to speed the setting or speed up calling of the function.
    – bmike
    Commented Jul 3, 2017 at 20:31
2

For others, one alternative I have found is to use the brightness command line tool, available via homebrew ( You can find instructions on how to install it from http://brew.sh ). Link to discussion: https://apple.stackexchange.com/a/127258/23876

The first line installs Brightness, the second shows you what brightness looks like in action.

brew install brightness
brightness 0; sleep 1; brightness 1

It only works on the main display though. If this form of brightness switching is too slow for you, experiment with sleep 0.3 or even sleep 0.1.

You can also get the current brightness so that you won't reset to 1:

setopt rematchpcre # needs zsh
if [[ "$(brightness -l)" =~ 'display 0: brightness (\S+)' ]]; then
    print -r -- "$match[1]"
else
    return 1
fi
4
  • something is missing ?
    – Ruskes
    Commented Apr 11, 2014 at 17:25
  • What is missing @Buscar?
    – studgeek
    Commented May 9, 2014 at 16:52
  • I tired it, and it does not work on my MBA 10.9.2 Error -bash: screenbrightness: command not found
    – Ruskes
    Commented May 9, 2014 at 17:06
  • @Buscar웃 The reason is that you don't actually have an app called screenbrightness. What you can do, is install Homebrew ( brew.sh ) and then do a "brew install brightness" - and then run "brightness 0; sleep 1; brightness 1" - for example.
    – esaruoho
    Commented Jun 1, 2017 at 17:19

You must log in to answer this question.

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