How I automatically run things after waking up my computer
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
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; suspend-resume.sh
Here’s the complete script:
#!/bin/bash icon="$HOME/.config/i3/lock.png" img="/tmp/i3lock.png" rm $img scrot $img convert $img -scale 10% -scale 1000% $img convert $img $icon -gravity center -composite $img case $1 in lock) suspend-resume.sh i3lock -u -i $img -n; suspend-resume.sh ;; suspend) suspend-resume.sh doas s2ram -f i3lock -u -i $img -n; suspend-resume.sh ;; esac
And this is what the
suspend-resume-sh script looks like:
#!/bin/bash weather.sh & /usr/bin/vdirsyncer sync & mbsync-notify.sh &
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.