4

xset dpms force off doesn't work, outputting:

X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  147 (DPMS)
  Minor opcode of failed request:  6 (DPMSForceLevel)
  Serial number of failed request:  12
  Current serial number in output stream:  14

I have two monitors that have power buttons on them, with default power management settings. However, pressing one keyboard shortcut using a command would be handy.

I'm pretty sure I'm using Gnome and read that xset doesn't work with Gnome.

As an alternative solution I'll just change the screen timeout to 1 minute.

Related:

  • OK, yeah that's what I thought. I think I'd rather just stay with Wayland for now. – James Ray Nov 23 '17 at 22:00
3

This script works on my Ubuntu 17.10

#!/bin/bash

busctl --user set-property org.gnome.Mutter.DisplayConfig /org/gnome/Mutter/DisplayConfig org.gnome.Mutter.DisplayConfig PowerSaveMode i 1
read -n 1 -s -r -p "Press any key continue"
busctl --user set-property org.gnome.Mutter.DisplayConfig /org/gnome/Mutter/DisplayConfig org.gnome.Mutter.DisplayConfig PowerSaveMode i 0
| improve this answer | |
  • I guess that this would work with something like autohotkey, but how would it be enabled in keyboard shortcuts? I tried entering #!/bin/bash;busctl --user set-property org.gnome.Mutter.DisplayConfig /org/gnome/Mutter/DisplayConfig org.gnome.Mutter.DisplayConfig PowerSaveMode i 1;read -n 1 -s -r -p "Press any key continue";busctl --user set-property org.gnome.Mutter.DisplayConfig /org/gnome/Mutter/DisplayConfig org.gnome.Mutter.DisplayConfig PowerSaveMode i 0 in as a command with a shortcut but it doesn't work. – James Ray Dec 27 '17 at 3:25
  • Could you create a .sh file with the above commands and access that file with a shortcut? – Gonki Dec 27 '17 at 18:40
  • Thanks, I worked it out. I just copied and pasted the commands into the file turnthescreenoff.sh which I saved in my home directory, then entered bash /home/james/turnthescreenoff.sh as a keyboard shortcut. – James Ray Dec 29 '17 at 4:06
  • Watch out: if anything pops up that covers the terminal, you need to go back to it with a dark screen – Pietro Battiston Feb 8 at 12:15
1

Ubuntu 17.10 runs a Wayland session by default, click the gear icon at login and choose a Xorg session instead if you need commands like xset. A common rule of thumb is that commands starting with x only run in Xorg. As far as I know Wayland doesn't provide a way to turn off the screen yet. This may very well change in the future though.

| improve this answer | |
1

Update 23 Mar 2018: alternatively you can set the power button to suspend rather than turn off. 24 Mar: however if you suspend it then the execution of all processes will be halted, which may not be desirable.

I entered the following commands made by @Gonki into the file turnthescreenoff.sh which I saved in my home directory, then entered bash /home/james/turnthescreenoff.sh as a keyboard shortcut.

#!/bin/bash

busctl --user set-property org.gnome.Mutter.DisplayConfig /org/gnome/Mutter/DisplayConfig org.gnome.Mutter.DisplayConfig PowerSaveMode i 1
read -n 1 -s -r -p "Press any key continue"
busctl --user set-property org.gnome.Mutter.DisplayConfig /org/gnome/Mutter/DisplayConfig org.gnome.Mutter.DisplayConfig PowerSaveMode i 0
| improve this answer | |
  • It didn't work for me : when I try to set a shortcut, it turns off the screen and immediately after, turns it on again. I guess it is due to the fact that the shortcut both runs the script and is seen by the script as the signal to turn on again the screen... So I even tried to add sleep 1s but it did not work. – Johannes Lemonde Jan 3 '18 at 19:24
  • OK, yes that happens to me too, I guess that I didn't wait long enough. – James Ray Jan 4 '18 at 3:08
  • It's not meant as a complete solution. I will wait for next Ubuntu where maybe it will be worked out. – Gonki Jan 14 '18 at 0:58
  • Fair enough, we will have to wait and use the power buttons or let power saver do the job in the meantime. – James Ray Jan 15 '18 at 23:53
  • Watch out: if anything pops up that covers the terminal, you need to go back to it with a dark screen – Pietro Battiston Feb 8 at 12:16
0

I took inspiration from Gonki and James Ray's answers and wrote a (python) version which runs without a shell:

#! /usr/bin/python3
import subprocess

template = ('busctl --user {what}-property org.gnome.Mutter.DisplayConfig '
            '/org/gnome/Mutter/DisplayConfig org.gnome.Mutter.DisplayConfig '
            'PowerSaveMode')

current = subprocess.check_output(template.format(what='get').split()).strip()
try:
    if current == b'i 0':
        subprocess.call(template.format(what='set').split() + ['i', '1'])
    else:
        subprocess.call(template.format(what='set').split() + ['i', '0'])
except:
    # If anything goes wrong, turn on the light:
    subprocess.call(template.format(what='set').split() + ['i', '0'])

It should solve the problem that Johannes Lemonde reported (that the screen would immediately turn on again), and hence will work with any hotkey: just press the same hotkey again to turn the screen on.

| improve this answer | |
  • Cool. I've switched to using Manjaro so I won't verify this. – James Ray Feb 7 at 4:16

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.