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.

share|improve this question
    
To assign custom key combination use these steps from Official ubuntu documentation – AndreyCh Nov 15 '15 at 20:59
3  
Possible duplicate of How to turn off monitor by hotkeys? – Cas Jan 26 '17 at 14:42
    
Reversing the direction of close (voting to leave this open) as this is the better post imho – Zanna Jan 26 '17 at 19:12

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

share|improve this answer
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 :) – spoke612 Dec 31 '13 at 10:42
    
Works great. When you move the mouse it comes back on. – Ciro Santilli 华涌低端人口 六四事件 法轮功 Jan 1 '15 at 21:04
5  
xset dpms force standby seems to be more reliable and doesn't need the sleep 1 ; xset dpms force off trick. – Alan Thompson Sep 17 '15 at 3:58

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!

share|improve this answer

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.

share|improve this answer

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

share|improve this answer
    
Great! The only working solution for Debian "Jessie" 8 with Gnome environment. – TranslucentCloud Jul 11 '17 at 18:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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