You could put together a script that you would use when hibernating, such that it first sets
gsettings set org.gnome.desktop.screensaver ubuntu-lock-on-suspend false
and then hibernates.
Then use another script that runs after resume (you do not need here to be selective about executing only upon resume from hibernation, as it could run upon resume from suspend as well, in which case it will have no effect), which sets
gsettings set org.gnome.desktop.screensaver ubuntu-lock-on-suspend true
I am not certain about the exact locations where to check/place for these scripts.
This idea is analogous to this script /lib/systemd/system-sleep/toggle-lock
, which might be very close to what you need
#!/bin/sh
set -e
if [ "$2" = "hibernate" ]; then
case "$1" in
pre)
XINPUTUSER=$(who | grep :0 | sed 's/([a-z])./\1/')
DISPLAY=:0.0 su - $XINPUTUSER -c "gsettings set org.gnome.desktop.screensaver ubuntu-lock-on-suspend false"
;;
post)
XINPUTUSER=$(who | grep :0 | sed 's/([a-z])./\1/')
DISPLAY=:0.0 su - $XINPUTUSER -c "gsettings set org.gnome.desktop.screensaver ubuntu-lock-on-suspend true"
;;
esac
fi
Notes:
- This asks about a similar issue, but with a much more specific target sequence of actions. Options there might be useful for you.
- The link above uses
pm
, while Ubuntu 20.04 uses systemd
. I am not certain they are "incompatible".
- Overall, I could look for the details to come up with a tentative step-by-step list of instructions. I often do that, but I also personally consider it is appropriate for an answer to promote a solution method, and the interested OP to take the method and fill in the gaps with further tinkering.
Related
- Correct way to execute a script on resume from suspend
- https://unix.stackexchange.com/questions/423524/script-that-is-executed-after-resuming-from-hibernation
- https://www.addictivetips.com/ubuntu-linux-tips/run-scripts-and-commands-on-suspend-and-resume-on-linux/