Inspired by this post.
It is interesting how simple specialised devices cope with their functions much better than a all-in-one PC. Sometimes, I wish to fall asleep with some music on. But how annoying it becomes, when you have to get up in the middle of the night to turn off your PC, which has been playing something all this time. Digital radios have mastered the trick decades ago. Of course there is a way to make a PC do it.
Running linux, I thought that it should be fairly straightforward to shut it down after say half an hour automatically.
Something like shutdown (below) will kill the X. The KDE then will just exit without saving the session. Next time you log on, you will see some session from a distant past. If you do this often, it gets really annoying. Also this requires superuser privileges on some distributions.
/sbin/shutdown -h now "Power button pressed" # or halt
Then how to make KDE quit without calling any dialogs (I am sound asleep by this time and I can’t afford to wake up and press ‘OK’)? There is a way.
dcop ksmserver ksmserver logout 0 2 2
The three numbers are explained below (see source):
First parameter: confirm
Obey the user’s confirmation setting: -1
Don’t confirm, shutdown without asking: 0
Always confirm, ask even if the user turned it off: 1
Second parameter: type
Select previous action or the default if it’s the first time: -1
Only log out: 0
Log out and reboot the machine: 1
Log out and halt the machine: 2
Third parameter: mode
Select previous mode or the default if it’s the first time: -1
Schedule a shutdown (halt or reboot) for the time all active sessions have
Shut down, if no sessions are active. Otherwise do nothing: 1
Force shutdown. Kill any possibly active sessions: 2
Pop up a dialog asking the user what to do if sessions are still active: 3