64

Since my monitor takes an awful lot of time to turn back on after being physically turned off, I'm looking for a command or a simple utility to turn off my screen with a shortcut. Setting a black screensaver is not satisfactory; I want the screen to "hibernate" (the same effect I would get by turning off the computer while leaving the screen physically on).

The same question for Windows: How can I make my screen blank by a shortcut?

octosquidopus
  • 1,350
  • 3
  • 12
  • 19

6 Answers6

84

Try using

xset dpms force off

to force the screen to turn off.

wizlog
  • 13,277
  • 24
  • 77
  • 116
Siva Charan
  • 4,865
  • 2
  • 25
  • 29
  • 4
    That's really great. For the OP though, when a key is pressed, it turns the screen back on. I'm not sure if that's desirable. – Brigand Jan 04 '12 at 21:18
  • 19
    Sometimes works better if you do `sleep 1 ; xset dpms force off` otherwise remnants of the last keyboard activity (I guess) sometimes turns the screen back on immediately. – Mat Jan 04 '12 at 21:19
  • 1
    This is exactly what I've been looking for. Thanks @siva-charan. The only thing I was wondering is how I could ask for a password when I wake the screen. I'm basically using a shortcut to turn off my screen and I would like it to ask for password on wake. – Isabel Inc Feb 06 '17 at 00:07
31

I made a file called /home/me/bin/blank and made it executable chmod +x blank with the following in it:

#!/bin/bash
sleep 1; xset dpms force off

Then I set a shortcut in Gnome3 application "keyboard" (gnome-control-center keyboard) to run that script when I push CTRL+ALT+Q.

Man I love linux.

hamstar
  • 529
  • 8
  • 11
4

I use Alex Cabal script to turn my two monitors screens off and on and it works very fine for me.

#!/bin/bash

# turn screens off/on
# (ɔ) alex cabal

screenOffLockFile=/tmp/screen-off-lock

if [ -f $screenOffLockFile ];
then
    rm $screenOffLockFile
    notify-send "Screen on." -i /usr/share/icons/gnome/48x48/devices/display.png
else
    touch $screenOffLockFile
    sleep .5
    while [ -f  $screenOffLockFile ]
    do
        xset dpms force off
        sleep 2
    done
    xset dpms force on
fi
almaceleste
  • 249
  • 1
  • 7
  • 1
    Generally, answers are much more helpful if they include an explanation of what the code is intended to do, and why that solves the problem without introducing others. – MMM Dec 18 '19 at 12:40
  • 2
    @MMM By clicking on the provided link, any interested user can go to a page of the original author of the script that explains in detail how it works. – Tropilio Feb 03 '20 at 16:51
  • 1
    Ideally answers are self contained so everything is still here if a linked site disappears. – Alan De Smet Dec 22 '21 at 15:38
3

As a premise, I personally prefer hamstar/Siva Charan solution. Anyway, I know another possible way could be a script that sets screensaver to blank and then make it start:

rem #!/bin/bash

xset s blank ; sleep 1 ; xset s activate

So as just not to let unspoken things

danicotra
  • 1,934
  • 2
  • 14
  • 25
  • ... And it seems like there's even a more complex one using python for this: https://www.howtogeek.com/61836/how-to-turn-off-your-monitor-with-a-hotkey-in-ubuntu/ (I didn't test it) – danicotra Jun 25 '17 at 11:26
3

You can go to your distro's settings, and add a shortcut => putting the command - xset dpms force off, then put a hotkey(say F9). That's it, whenever you hit the hotkey, your monitor's screen will turn off

tavish
  • 31
  • 3
2

slock locks the screen gracefully.

octosquidopus
  • 1,350
  • 3
  • 12
  • 19