9

Now I have two scripts and I want to execute them respectively when I close the laptop lip and open it. How can I do this?

bearsiji
  • 91
  • 1
  • 2
  • The answer by Rafael in [this question](http://askubuntu.com/questions/64570/how-do-i-configure-the-screen-to-lock-when-i-close-the-lid/68483#68483) might give you some ideas. – Kevin Bowen Apr 14 '13 at 08:05
  • 2
    https://help.ubuntu.com/community/LaptopLidAndDockScripts explains it. – Rinzwind Apr 14 '13 at 08:05
  • 2
    What is the action when your laptop lid is closed: hibernate, suspend or do nothing? – Radu Rădeanu Sep 04 '13 at 05:12
  • Did you find a way already? I try to do something similar: [Disable touchscreen on closing laptop lid](http://askubuntu.com/q/525878). So if you know a way please answer your own question here – rubo77 Sep 19 '14 at 11:13
  • @Rinzwind: this is last updated in 2012 and it seems really complicated – rubo77 Sep 19 '14 at 11:38
  • Considering that the lid closure dims the light and finally dims to zero...polling for the brightness value in the backlight folder in etc directory can help run a script at laptop lid closing.. – cafebabe1991 Aug 13 '15 at 14:36
  • Laptop Lid close is noticed by the Power Management system, which, happily enough, has hooks for additional user actions built in. This will get you started: `less /usr/share/doc/pm-utils/*` – waltinator Aug 17 '15 at 18:11

1 Answers1

2

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.

Arch User
  • 59
  • 4