6

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.

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
  • 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 Jul 3 '17 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 Jul 3 '17 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.

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

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.

  • something is missing ? – Ruskes Apr 11 '14 at 17:25
  • What is missing @Buscar? – studgeek May 9 '14 at 16:52
  • I tired it, and it does not work on my MBA 10.9.2 Error -bash: screenbrightness: command not found – Ruskes May 9 '14 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 Jun 1 '17 at 17:19
1

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"
  • 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 Jul 3 '17 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 Jul 3 '17 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 Jul 3 '17 at 20:31
0

This is a shellscript that calls applescript to do this (the code needs to be explained more)

#!/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

You must log in to answer this question.

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