38

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

4 Answers 4

34

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, 2013 at 10:34
  • 1
    Yeah sorry I'm new here and have some problems with > Thank you :)
    – eriv
    Dec 31, 2013 at 10:42
  • Works great. When you move the mouse it comes back on. Jan 1, 2015 at 21:04
  • 9
    xset dpms force standby seems to be more reliable and doesn't need the sleep 1 ; xset dpms force off trick. Sep 17, 2015 at 3:58
29

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

2
  • Great! The only working solution for Debian "Jessie" 8 with Gnome environment. Jul 11, 2017 at 18:27
  • Still the only one that works for me in Ubuntu 22.04
    – Jeff
    Apr 24, 2023 at 3:31
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, 2020 at 15:44

You must log in to answer this question.

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