0

I'm running Ubuntu 22.04.2 LTS and want to display the lock screen when I unplug my charger. Is there a script, plugin or program that will let me do this?

1 Answers1

0

tl;dr:

sudo bash -c 'cat << EOF > /etc/udev/rules.d/80.lock_when_unpluged.rules
ACTION=="change", SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/bin/loginctl lock-sessions"
EOF'
# ... and reboot

Tested on ubuntu 20.04 and 22.04


I have a file at /etc/udev/rules.d/80.lock_when_unpluged.rules, and it works like a charm :

# /etc/udev/rules.d/80.lock_when_unpluged.rules 
ACTION=="change", SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/bin/loginctl lock-sessions"

I needed a reboot

Source https://unix.stackexchange.com/questions/227918/system-event-on-ac-adapter-insert-or-battery-unplugged