Skip to content

Creating Laptop Lid Open/Close Scripts

To make something happen on opening and closing the laptop lid scripts can be created to handle it.

Execution

Create event config file

Create file /etc/acpi/events/lm_lid.

Insert the following content:

event=button/lid.*
action=/etc/acpi/lid.sh

Create script file

Create file /etc/acpi/lid.sh to handle the events.

#!/bin/bash

# Check if the lid of the laptop is closed.
grep -q close /proc/acpi/button/lid/*/state

if [[ $? = 0 ]] ; then

    xrandr --output LVDS1 --off
    xrandr --output HDMI1 --auto
    logger "Switching laptop monitor OFF"
    echo "Switching laptop monitor OFF"

fi        


# Check if the lid of the laptop is open.
grep -q open /proc/acpi/button/lid/*/state
if [ $? = 0 ] ; then

    xrandr --output LVDS1 --auto
    #xrandr --output HDMI1 --auto
    logger "Switching laptop monitor ON"
    echo "Switching laptop monitor ON"

fi