<SOLVED> Keyboard shortcut to turn off monitors doesn't work

Please post suggestions for improvement of Cinnamon on:
https://github.com/linuxmint/Cinnamon
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Gsparky2004
Level 2
Level 2
Posts: 51
Joined: Mon Apr 27, 2015 10:27 pm

<SOLVED> Keyboard shortcut to turn off monitors doesn't work

Post by Gsparky2004 »

I'm running Linux Mint 17 Qiana on a quad-core, 64-bit system. My video card is a nVidia GEForce 210 running to two monitors. I wanted to create a keyboard shortcut to turn off my monitors without physically turning them off. Essentially, do the same thing when I leave the computer sitting for 15 minutes and the monitors go into sleep mode (or whatever it's called). I went to Keyboard -> Keyboard Shortcuts -> Custom Shortcuts. I added a custom shortcut for the following command, "xset dpms force off". Then I bound that to a particular keyset (Ctrl + F3).

The problem is that, every time I use it, the monitors turn off, then they turn back on after about a second. I've tried different key bindings, but they all wind up with the same result. Monitors turn off, then right back on.

I tried the command (xset dpms force off) from a terminal, and it works fine from there. That's my work-around unless and until I can find a solution to this particular problem. This is an annoyance, really, not a serious issue. I've also searched the forums here to see if anyone has had a similar problem. I've not found anyone who has. Sooooo, any help would be appreciated.
Last edited by Gsparky2004 on Tue Apr 28, 2015 8:04 pm, edited 1 time in total.
Linux Mint 21.2 Cinnamon controlling an Intel i9-13900 with MSI Z790 mobo, 128 GB of RAM and MSI Nvidia GeForce RTX 4060 16GB video card.
niowluka

Re: Keyboard shortcut to turn off monitors only works for 1

Post by niowluka »

Try adding a 1 second delay:

Code: Select all

sleep 1 && xset dpms force off
I used to have the same problem on my old rig. From what I remember it's because without the delay the command is executed immediately after pressing the shortcut key, and then when you release the key, kernel detects it as an event and wakes up the monitor.
Gsparky2004
Level 2
Level 2
Posts: 51
Joined: Mon Apr 27, 2015 10:27 pm

Re: Keyboard shortcut to turn off monitors only works for 1

Post by Gsparky2004 »

Thanks for the response, niowluka. Unfortunately, adding the "sleep 1 &&" before the "xset" command makes it so that nothing happens at all. With the "xset dpms force off" alone, the monitors turn off, then right back on. With the "sleep 1 &&" in front, absolutely nothing happens at all.

What's weird is that it works perfectly if I run the command from the terminal. I type in "sleep 1 && xset dpms force off", press (Enter), and the monitors turn off 1 second later. If I put that in as a keyboard shortcut, absolutely nothing happens at all when I press the appropriate keys.

Thanks again, and please let me know if you have any other ideas.
Linux Mint 21.2 Cinnamon controlling an Intel i9-13900 with MSI Z790 mobo, 128 GB of RAM and MSI Nvidia GeForce RTX 4060 16GB video card.
niowluka

Re: Keyboard shortcut to turn off monitors only works for 1

Post by niowluka »

Try adding this as shortcut:

Code: Select all

sh -c "sleep 1 && xset dpms force off"
Gsparky2004
Level 2
Level 2
Posts: 51
Joined: Mon Apr 27, 2015 10:27 pm

Re: Keyboard shortcut to turn off monitors only works for 1

Post by Gsparky2004 »

BINGO! That works perfectly! Thank you, niowluka! I'm marking this as solved.

Let me guess. The "sh" invokes a shell (dash?), and the "-c" switch tells the system to treat what follows as if it came from the command line. Did I get that right?

Thanks again! :D
Linux Mint 21.2 Cinnamon controlling an Intel i9-13900 with MSI Z790 mobo, 128 GB of RAM and MSI Nvidia GeForce RTX 4060 16GB video card.
niowluka

Re: <SOLVED> Keyboard shortcut to turn off monitors doesn't

Post by niowluka »

Gsparky2004 wrote:The "sh" invokes a shell (dash?), and the "-c" switch tells the system to treat what follows as if it came from the command line. Did I get that right?
Yes. You could have used 'bash' instead, or whatever the shell you prefer, 'sh' is just more general.

I think without passing the command to shell, the keyboard shortcut app-thing was getting confused by '&&', that's why it wouldn't work at all with 'sleep'.
Gsparky2004
Level 2
Level 2
Posts: 51
Joined: Mon Apr 27, 2015 10:27 pm

Re: <SOLVED> Keyboard shortcut to turn off monitors doesn't

Post by Gsparky2004 »

I think without passing the command to shell, the keyboard shortcut app-thing was getting confused by '&&', that's why it wouldn't work at all with 'sleep'.
Groovy. It works perfectly now, and I even found that sleep will accept floats, so I shortened it to 0.25. Now when I hit Ctrl + F3, the monitors turn off instantly.

For anyone coming here looking for the final solution to turn your monitors off (put them in hibernate or sleep mode), these are the steps:

1. Open the "Keyboard" widget. I did this by going to the "Dash" and typing "keyboard". The "Keyboard" application should appear on right. Click on it.
2. Click on the "Keyboard Shortcuts" tab.
3. Click on "Custom Shortcuts".
4. Click on the "Add Custom Shortcut" at the bottom of the panel.
5. In the window that pops up, give it a descriptive title where it says "Name". I put in "Turn off monitors".
6. In the part that says "command", put in

Code: Select all

sh -c "sleep 0.25 && xset dpms force off"
7. Click "Add". It should now appear in the list of shortcuts.
8. In the section where it says "Keyboard bindings", click where it says "unassigned". (Note: You might have to click it more than once. Mine was a bit touchy.)
9. Once it is highlighted, type in the key combination that you want to use. I used Ctrl + F3 (hit the control key plus F3 at the same time).
10. That's it! You should be able to close the "Keyboard" window and it should work!

Thanks again to niowluka for rocking this forum!
Linux Mint 21.2 Cinnamon controlling an Intel i9-13900 with MSI Z790 mobo, 128 GB of RAM and MSI Nvidia GeForce RTX 4060 16GB video card.
richardm317
Level 1
Level 1
Posts: 38
Joined: Mon Oct 22, 2018 12:37 am

Re: <SOLVED> Keyboard shortcut to turn off monitors doesn't work

Post by richardm317 »

I know the rules say to not bring back threads over six months but this information remains perfectly relevant to Mint 19. I wanted to both lock my workstation and power off the monitors from a single keybinding. I ended up with the following assigned to ctrl+alt+L:

Code: Select all

sh -c "sleep 1 && xdg-screensaver lock && xset dpms force off"
Very happy with how this works.
Locked

Return to “Cinnamon”