Catch lid close and open events

I tried to write a script like this suggestion:

How do I configure the screen to lock when I close the lid?

I created a directory and a new script file:

mkdir /etc/acpi/local
gksudo gedit /etc/acpi/local/lid.sh.post

The file /etc/acpi/local/lid.sh.post with the following code:

#!/bin/sh

#########################################################################
## Script written by Ruben Barkow                                      ##
## https://gist.githubusercontent.com/rubo77/1a3320fda5a47fdebde7/raw/87cde3f0554467a132aba3cda7ad3c5e7187571f/lid.sh.post
## Description: This script reacts if laptop lid is opened or          ##
## closed in Ubuntu 11.10 (Oneiric Ocelot).                            ##
##                                                                     ##
## This script can be freely redistributed, modified and used.         ##
## Any redistribution must include the information of authors.         ##
##                                                                     ##
## THIS SCRIPT HAS NO WARRANTY!                                        ##
#########################################################################

grep -q close /proc/acpi/button/lid/*/state
if [ $? = 0 ]; then
    echo close>>/tmp/screen.lid
fi
grep -q open /proc/acpi/button/lid/*/state
if [ $? = 0 ]; then
    echo open>>/tmp/screen.lid
fi

I tried to get this running in Ubuntu 14.04, but why this has no effect.

Is there a new way in Ubuntu 14.04 to catch the lid close and open events?


I got a hint here: https://askubuntu.com/a/518825/34298

  • The script you want to call when the lid opens or closes has to be stored
    in /etc/acpi/lid.sh.

  • Then there has to be created the correct file /etc/acpi/events/lm_lid with the content as follows:

    event=button/lid.*
    action=/etc/acpi/lid.sh
    
  • Reboot your system to let this take effect. Or maybe it is enough to restart your ACPI using

    sudo /etc/init.d/acpid restart