Per the title, I’d like to use this timer to say “Do X” (in my case xscreensaver-command --activate) after ten minutes of inactivity and then turn off the screen after thirty but I can’t seem to find a way to do so.
you can script all of that and set the plasma controls to “do nothing”
then just have it execute the script after you idle timeout which can start another timer to issues sleep or hibernate after an additional period.
script items that appear after the sleep / hibernate command will be executed when it resumes.
You make it sound so easy but the closest I’ve ever got to scripting was making a little bash file I can run to add virtual audio sinks and loopbacks which at one point I had configured to run on login but since prevented.
To be exact, I made this:
#!/bin/bash
# Create Null Sink and Loopback For OBS
pactl load-module module-null-sink media.class=Audio/Sink sink_name="OBSAudio"
pactl load-module module-loopback sink="alsa_output.usb-SMSL_SMSL_USB_AUDIO-00.analog-stereo" source="OBSAudio.monitor"
# Create Null Sink and Loopback For Discord
pactl load-module module-null-sink media.class=Audio/Sink sink_name="Discord_Audio"
pactl load-module module-loopback sink="alsa_output.usb-SMSL_SMSL_USB_AUDIO-00.analog-stereo" source="Discord_Audio.monitor"
I’ve done some googling on how to make such scripts and got nothing helpful.
the controls provided are limited to timers for the screen locking and then for sleep.
only the sleep function has the option to run a script, so that is your only pathway into doing your own thing short of digging into the code.
so if you have gotten as far a writing an executable script and have been able to use it, then it’s just a matter of entering the name into the power management settings page and setting up the timer.
what the script does is up to you.
what are you trying to accomplish?
if you have terminal commands that already do what you want, it’s just a matter of putting them into the script in the order you want the to occur.
I’m trying to accomplish having the system invoke xscreensaver when it’s been active for ten minutes and then turn the screen off after twenty more minutes.
My original plan was to use the “Other Settings” option to run command or script to achieve this but during testing that only checked for user input and thus cut in when I was running videos. The “Display and Brightness” timer doesn’t have this issue which is why I wanted to use it but I simply do not know how.
i assume you already have an xscreensaver command that does what you want?
there is also a screen locking feature in plasma the brings up a wallpaper of your choosing, are you using that as well? … they could conflict.
in power settings you would set the screen to power off after 30 min
and under run script, set it to run after 10min and give it the name of a script that runs that command for you.
when the 10 min mark hits, it should evoke the screen saver, and then at the 30 min mark it should turn off the screen.
the computer will continue to run unless you also have the suspend option enabled with a timer for say 1hr before it goes to sleep.
I do have that command and I made a point to disable locking. My Power Management looks like this:
Just to be certain I tested it before I posted this and it did indeed call the screensaver in the middle of a fullscreen youtube video, as you can imagine this is somewhat frustrating. For sanity testing I also set the screen turn off to one minute afterwards and fullscreened my video again and per my desired behaviour it did not turn off.
Sorry if I come off as difficult, I do appreciate advice and I understand I’m trying to do something the system appears designed not to do - or I’ve come up on a bug.
so the behavior you have found is that the screen will not lock while the video is playing, and that’s the behavior you want to transfer to the screensaver script.
you just need to add to the script a way to check if the “block sleep and screen locking” is active and to wait until it is not before running the rest of the script.
you may also want to change the time to turn off the screen to
never and when locked 5 min
so that it will turn off the screen only after the screen locking finally kicks in.
you can also control this manually from system tray by using this check box
here is another thread about this sort of thing you may find useful.
I got this: busctl --user call org.kde.Solid.PowerManagement.PolicyAgent /org/kde/Solid/PowerManagement/PolicyAgent org.kde.Solid.PowerManagement.PolicyAgent ListInhibitions from this thread which appears to output the information needed, so I suppose I need a way to read the output of that and say: if “aas 0” then run screensaver, else wait 600 seconds.
yes, that’s the idea.
mine says
a(ss) 0
when there is nothing preventing the screen locking…
Bearing in mind I am very much not a coder, would something along the lines of this work?
watch -n 2 "busctl --user call org.kde.Solid.PowerManagement.PolicyAgent /org/kde/Solid/PowerManagement/PolicyAgent org.kde.Solid.PowerManagement.PolicyAgent ListInhibitions" |
while read aas 0; do
case "$aas 0" in
*"boolean true"*) xscreensaver-command --activate;;
*"boolean false"*) ;;
esac
done
best way to find out is to run it in a terminal, don’t forget the shebang as the first line and to make the file executable.
as for the code, i would have probably gone a different route using shell variables, but at first glance it seems like it could work.
the basic logic seems to be there
you can always use echo to output onto a terminal window what the script is doing to troubleshoot if you need to.
(I’m assuming this is bash, if this isn’t - there may be more than the issues I commented on)
The watch command doesn’t do what you think it does - its a TUI (Text User Interface) that doesn’t output anything, instead it draws on the screen. If you are running it in a script - it will output nothing.
If you want to loop (“monitor”) while checking the output of a command, its best to do a loop:
function watchInhibitions() {
while true; do
busctl --user call org.kde.Solid.PowerManagement.PolicyAgent /org/kde/Solid/PowerManagement/PolicyAgent org.kde.Solid.PowerManagement.PolicyAgent ListInhibitions
sleep 2
done
}
watchInhibitions | while read prefix count otherstuff; do
if ((count <= 0)); then
xscreensaver-command --activate
fi
done
(also, your read syntax and results handling are completely wrong, but I got the idea and fixed it for you).
Please note that this script will run forever - this is not something to be launched every timeout. You either want to run it in the background of your session, or have some kind of stop condition.
Here’s an improved version that stops if the screensaver activates and then deactivates.
This is still not a good script to run on an idle timeout, because it doesn’t detect if a user has become idle while sleep is inhibited, and then - before the inhibition is removed - starts being active again. If this will happen, you will get a surprise screen saver.
function watchInhibitions() {
while true; do
busctl --user call org.kde.Solid.PowerManagement.PolicyAgent /org/kde/Solid/PowerManagement/PolicyAgent org.kde.Solid.PowerManagement.PolicyAgent ListInhibitions
sleep 2
done
}
watchInhibitions | while read prefix count otherstuff; do
if ((count <= 0)); then
xscreensaver-command --activate
xscreensaver-command --watch | while read event otherstuff; do
if [ "$event" = "UNBLANK" ]; then exit; fi
done
fi
done
I’ve adjusted the title to better reflect the goal
First, thank you helping this much. Second could this be mitigated by checking the idle timer? Along the lines of: ‘if idletime<600 (assuming seconds) then exit, else continue’?
I looked around on the internet for a bit and discovered this command: busctl --user call org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver GetSessionIdleTime but on my system that returns: Call failed: GetSessionIdleTime is not supported on this platform
I also got pointed to: loginctl show-session “$XDG_SESSION_ID” -p IdleHint -p IdleSinceHint which at a glance looks like it’s useful. I put this together using the previous example:
function checkIdle() {
while true; do
loginctl show-session “$XDG_SESSION_ID” -p IdleHint -p IdleSinceHint
done
}
checkIdle | while read prefix count otherstuff; do
if ((count =0)); then
print="No"; fi
done
That resulted in an endless stream of Failed to get path for session '“2”': No session '“2”' known I’m guessing either the function is wrong or I’m misusing the original command, or both.
Make sure to use straight quotes, not curly quotes - so "$XDG_SESSION_ID" instead of “$XDG_SESSION_ID”.
Thanks, that lead to more progress, I’ve got to this:
function checkIdle() {
while true; do
loginctl show-session "$XDG_SESSION_ID" -p IdleHint -p IdleSinceHint
done
}
checkIdle | while read prefix count otherstuff; do
if ((count <=0)); then
echo No
exit; fi
done
Which seems to function, in that it says “No”. So I’ve put the two functions together as below, should it work?
function watchInhibitions() {
while true; do
busctl --user call org.kde.Solid.PowerManagement.PolicyAgent /org/kde/Solid/PowerManagement/PolicyAgent org.kde.Solid.PowerManagement.PolicyAgent ListInhibitions
sleep 2
done
}
function checkIdle() {
while true; do
loginctl show-session "$XDG_SESSION_ID" -p IdleHint -p IdleSinceHint
done
}
checkIdle | while read prefix count otherstuff; do
if ((count <=600)); then
exit; else
watchInhibitions | while read prefix count otherstuff; do
if ((count <= 0)); then
xscreensaver-command --activate
xscreensaver-command --watch | while read event otherstuff; do
if [ "$event" = "UNBLANK" ]; then exit; fi
done
fi
fi
done
done

