35

How can I make a script (or make some changes) to allow me to turn the screen off in Ubuntu (12.04) whenever I want, the way thevscreen can be turned off in Cellphones?

And how can I make a combination of keys (a shortcut) to execute that script?

I want to conserve power.

I've seen this question

Turning Monitor Off With an Icon but there is no hotkey for it.

Moreover, in the answer, it is said that there are many ways to accomplish this so I'd like to know more.

3
33

If I understood well your question, you could use this commmand

xset dpms force off

In your settings, go to keyboard, shortcut, click on plus, write the name you want and past the command I just wrote, click on the new short cut and use the combination or key you want to use

4
  • 2
    xset dpms force off? :-)
    – Wilf
    Dec 31 '13 at 10:34
  • 1
    Yeah sorry I'm new here and have some problems with > Thank you :)
    – eriv
    Dec 31 '13 at 10:42
  • Works great. When you move the mouse it comes back on. Jan 1 '15 at 21:04
  • 8
    xset dpms force standby seems to be more reliable and doesn't need the sleep 1 ; xset dpms force off trick. Sep 17 '15 at 3:58
25

Custom shortcuts to do this with newer versions of Ubuntu (e.g. 16.04) seems to require a delay from pressing the key combination to running the command. The simplest solution is to modify the shortcut command using sh.

Go to System Settings... | Keyboard | Shortcuts | Custom Shortcuts. Create a new custom shortcut and in Command put:

sh -c 'sleep 0.3 && xset dpms force off'

You can change the delay but I found 0.1s was not quite enough sometimes.

enter image description here

1
  • Great! The only working solution for Debian "Jessie" 8 with Gnome environment. Jul 11 '17 at 18:27
12

The command is xset dpms force off

Just create a keyboard shortcut for it. Go to keyboard->shortcuts....go to custom shortcuts.....& then click on the + icon to create a new shortcut.

Then assign the above & assign custom key combination.

enter image description here

DONE!

0
9

At the beginning I also configured a key shortcut with

xset dpms force off

But after 2 seconds the display turned on again. Maybe my newer Ubuntu Version (15.05) is the reason for this different behaviour. The solution was to create a script with the following content:

#!/bin/bash

sleep 1 && xset dpms force off

Now call this script every time you press the shortcut.

I think this method works because of any delayed key press event. With the sleep command all key events have 1 second to be processed and they do not wake the screen up again.

1
  • Please also mention how to link the script file to the shortcut Jun 17 '20 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.