How I automatically run things after waking up my computer

Tuesday, June 22, 2021

Some time ago, Gentoo deprecated pm-utils, which didn’t come as a surprise considering it hasn’t been updated upstreams for 11 years now.

pm-utils was a small collection of scripts that handles suspend and resume on behalf of HAL. One of the things that pm-utils allowed me to do, was to automatically run any scripts when I woke up the computer.

With the deprecation of pm-utils, I was left with two alternatives; 1) elogind (the systemd project’s logind, extracted to a standalone package) and 2) s2ram. Considering the fact that I’m not a big fan of systemd, I really only had one choice.

While s2ram works just fine, it does lack the ability to automatically run scripts when waking up my computer. To work around this, I modified my i3lock script to run another script called

The solution

After a few tries, I figured out that I needed the flag -n, --nofork for i3lock to get it execute a command after waking up my computer and unlocking the screen:

i3lock -n; 

Here’s the complete script:



rm $img
scrot $img
convert $img -scale 10% -scale 1000% $img
convert $img $icon -gravity center -composite $img

case $1 in
        i3lock -u -i $img -n; 
        doas s2ram -f
        i3lock -u -i $img -n; 

And this is what the suspend-resume-sh script looks like:

#!/bin/bash &
/usr/bin/vdirsyncer sync & &

I actually ended up liking this solution a lot more than the old one with pm-utils, because this is all run by my own user and not as root pretending to be me.



If you want to leave any feedback, feel free do so by either sending me a message via e-mail, XMPP or IRC.