This command does successfully put the computer to sleep (and thus the screens eventually go dark and no longer light up the room like stadium lighting):
echo freeze > /sys/power/state
But mere mortals don’t have permission to do that.
I added a script in /etc/init.d which does a chmod 666 /sys/power/state on startup (see the previous post about editing /etc/init.d/after.local)
Credit where credit is due: a gentleman named Aaron Ball posted this at his web site oper.io – clever logo, too, to combine the power switch icon as “.io” – but I digress.
Then another tiny script that simply does the echo command for me:
#!/bin/sh
/usr/bin/echo freeze > /sys/power/state
I had started to go down the road of a sudoers file entry, which would give anyone permission to run this script; but the problem isn’t who runs the command. The problem is that the target of the echo command, /sys/power/state, isn’t going to allow writing by a script (even if run by sudo).
Last step was to add a keystroke to my KDE shortcuts. System Settings –> Custom Shortcuts –> Edit –> New –> Global Shortcuts
Name the action, assign the keystrokes to invoke it, and make the action the tiny script above. Works like a charm. 🙂