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

Please post suggestions for improvement of Cinnamon here
https://github.com/linuxmint/Cinnamon
Locked
Gsparky2004
Level 1
Level 1
Posts: 11
Joined: Mon Apr 27, 2015 10:27 pm

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

Post by Gsparky2004 » Mon Apr 27, 2015 10:46 pm

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.

niowluka
Level 5
Level 5
Posts: 730
Joined: Tue May 27, 2014 6:28 pm
Location: Krakow, Poland

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

Post by niowluka » Tue Apr 28, 2015 3:15 am

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.
Mint 17 Openbox (MATE) 64bit | Linux 4.1.6 (Vanilla)

Gigabyte GA-880GA-UD3H | AMD Phenom II X4 965 3.4Ghz | G.Skill 8GB DDR3-1600 RipjawsX, F3-12800CL8D-8GBXM | MSI R7 260X 2048 MB GDDR5 OC

Gsparky2004
Level 1
Level 1
Posts: 11
Joined: Mon Apr 27, 2015 10:27 pm

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

Post by Gsparky2004 » Tue Apr 28, 2015 7:45 am

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.

niowluka
Level 5
Level 5
Posts: 730
Joined: Tue May 27, 2014 6:28 pm
Location: Krakow, Poland

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

Post by niowluka » Tue Apr 28, 2015 8:56 am

Try adding this as shortcut:

Code: Select all

sh -c "sleep 1 && xset dpms force off"
Mint 17 Openbox (MATE) 64bit | Linux 4.1.6 (Vanilla)

Gigabyte GA-880GA-UD3H | AMD Phenom II X4 965 3.4Ghz | G.Skill 8GB DDR3-1600 RipjawsX, F3-12800CL8D-8GBXM | MSI R7 260X 2048 MB GDDR5 OC

Gsparky2004
Level 1
Level 1
Posts: 11
Joined: Mon Apr 27, 2015 10:27 pm

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

Post by Gsparky2004 » Tue Apr 28, 2015 8:02 pm

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

niowluka
Level 5
Level 5
Posts: 730
Joined: Tue May 27, 2014 6:28 pm
Location: Krakow, Poland

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

Post by niowluka » Wed Apr 29, 2015 3:03 am

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'.
Mint 17 Openbox (MATE) 64bit | Linux 4.1.6 (Vanilla)

Gigabyte GA-880GA-UD3H | AMD Phenom II X4 965 3.4Ghz | G.Skill 8GB DDR3-1600 RipjawsX, F3-12800CL8D-8GBXM | MSI R7 260X 2048 MB GDDR5 OC

Gsparky2004
Level 1
Level 1
Posts: 11
Joined: Mon Apr 27, 2015 10:27 pm

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

Post by Gsparky2004 » Wed Apr 29, 2015 6:03 am

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!

richardm317
Level 1
Level 1
Posts: 10
Joined: Mon Oct 22, 2018 12:37 am

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

Post by richardm317 » Sun Nov 04, 2018 4:57 am

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”