-
su -
echo 'event=button/lid.*' >> /etc/acpi/events/lm_lid -
echo 'action=/etc/acpi/lid.sh' >> /etc/acpi/events/lm_lid -
Find out your session type:
$XDG_SESSION_TYPE -
vi /etc/acpi/lid.sh:Change USERNAME to your username (
whoami)X11:
#!/bin/bash grep -q close /proc/acpi/button/lid/*/state if [ $? = 0 ] then # Close action sleep 1 su -c "xset -display :1 dpms force off" - USERNAME else # Open action su -c "xset -display :1 dpms force on &> /tmp/screen.lid" - USERNAME fiIf not working, replace
:1with the output ofecho $DISPLAYWayland:
#!/usr/bin/env bash grep -q close /proc/acpi/button/lid/*/state if [ $? = 0 ] then # Close action sleep 1 su -c "busctl --user set-property org.gnome.Mutter.DisplayConfig /org/gnome/Mutter/DisplayConfig org.gnome.Mutter.DisplayConfig PowerSaveMode i 1" - USERNAME else # Open action su -c "busctl --user set-property org.gnome.Mutter.DisplayConfig /org/gnome/Mutter/DisplayConfig org.gnome.Mutter.DisplayConfig PowerSaveMode i 0" - USERNAME fi -
chmod +x /etc/acpi/lid.sh -
/etc/init.d/acpid restart
Tested on
- Ubuntu 18.04