Run script when user returns from idle

Hello

I think it is very handy that in Power Management, you can run a script when idle. However, it is a bit of a shame there is no possibility to run a script when the user is back.

Should I do a feature request maybe? Can you do that on bugs.kde.org ?

if you run the script at idle, it will “complete” the next part of the script upon wake.

#!/bin/bash

echo "hey it's now $(date)" >> ~/bin/timestamp

sudo systemctl suspend-then-hibernate

sleep 5

echo "but now it's $(date)" >> ~/bin/timestamp
echo "********************" >> ~/bin/timestamp

#this will re-apply the RGB profile to the RAM modules which always wake up in rainbow
~/.local/bin/OpenRGB_0.9_x86_64_b5f46e3.AppImage --profile amber

the timestamp file records the time/date before suspend and then immediately after wake.

then it also runs a script to set the color of my ram sticks after hibernation because when they lose power they go back to rainbow by default.

Hello and thanks for the reply.

I don’t want my sustem to suspend or hibernate though. :relieved_face:

you would just use a different systemctl command in that case… mine was just an example.

the point is you have to go into idle using the script in order for the script to complete upon wake.

When you say “idle”, you mean “inactive” right, as in this part of the settings?

i.e. the user has gone N minutes without activity.


And when you say “idle”, you’re referring to some power management state, right?

So maybe a case of terminology being at cross-purposes.

2 Likes

Yes I was refering to that part of the settings.

I hope idle and inactive mean the same thing? As in, no user interaction for x amount of time. Ah but I see, you were thinking of thing like cpu idleness? No, I meant it purely in user activity terms.

I needed something that does something when the system becomes idle (as in me not active for a couple of minutes), and does another thing when I resume my work.
I found the systemctl thing to be a bit of a hassle, and it’s not too clear when or how the idle flags actually flip or not.

I ended up making my own thing, which queries last mouse movement by reading out /dev/input/mice

I wonder if you could react to the ActiveChanged D-Bus signal of the org.freedesktop.ScreenSaver service instead.

1 Like

Indeed, Claude suggested it as well, and it works, but I ended up not using it since it is still not clear how and when the system deems the user inactive.

With the mouse query, I have my exact timings I want. This could be extended to all input devices ofcourse, but the mouse if enough for now.