I’ve been looking for a command line way to switch KDE5 power management to suspend or to hibernate, so I can have a script which will, when I wake the computer, set the next sleep according to whether it’s day or night, i.e. after 11pm, hibernate at next sleep, after 8am suspend at next sleep.
Can anyone point me to the right bit of documentation / dbus commands / whatever?
Thanks
David
p.s. I’ve searched, and there’s lots of old stuff that no longer works, but nothing recent I can see …
KDE’s power management utility can be configured to run a script after a certain period of inactivity. Such a script could check the current time, then suspend (‘systemctl suspend’ command) or hibernate (‘systemctl hibernate’ command) as appropriate
System Settings > Power Management > Energy Saving > Run Script…
Another related question: I was trying to be clever and not sleep if certain jobs are running (ffmpeg, transcode for media conversion unison, rsync for backups etc.). I have two options for this: return a non-zero return code; or wait until the job has finished and do the sleep then. The former is dependent on whether (and when) the power management software retries later if the sleep fails, and the later would benefit if the script could recognise if someone had removed / closed the screen locker.
Is there a “universal” (within X11) way to tell if a screen locker has locked the screen?
A word of warning about this script: it won’t detect if a program (e.g. dd) is being run by another user (e.g. as root using sudo)!
This deficiency can be fixed using additional entries in /etc/sudoers to permit killall -s 0 - [A-Za-z0-9]* (not tested) and more code in the script to detect if this is present and use it if so, but this is too much messing about for me now.
If someone fixes this, please repost or put on githib …