Execute a shell-script when closing laptop lid
Solution 1:
Use acpi:
The event is handled by acpi:
$ sudo nano /etc/acpi/handler.sh
I did something like this:
button/lid)
case "$3" in
close)
logger 'LID closed'
USER=$(ps -C i3 -o user=)
if test $USER; then DISPLAY=:0.0 su $USER -c "/usr/bin/i3lock -i /usr/share/pixmaps/Screensaver.png"; fi
;;
Automatically starts i3lock when i close my lid.