18

I have a weird problem where my laptop will wake when it's closed, generating a lot of heat and causing much frustration.

Is there a way that I can tell if the laptop's lid is closed so that I can automatically suspend the computer (via a cron script) if it wakes itself while the lid is closed?

Closing the lid does currently suspend the machine and opening it does wake it, so that works properly. It's a 2011 MacBook Pro running Ubuntu 12.04.

1
  • I'm having a similar issue with a Dell laptop running Arch Linux. Commented Aug 3, 2014 at 22:30

2 Answers 2

28

For my specific case, I can get the status of the lid with

$ cat /proc/acpi/button/lid/LID0/state state: open 

I can then just grep for open or closed to see if it's open or closed.

4
  • To note: this works on my MacBook Pro, a Dell laptop, and a Gateway laptop also, so I'm assuming this is fairly ubiquitous. Commented Aug 6, 2014 at 21:50
  • 1
    How about 2 in 1 notebooks that can have lid 360° opened? is there an indication or should we use some combination of lid open and accelerometer readings? Commented Apr 24, 2017 at 21:00
  • 1
    Answering to my own comment, I put hands on 2 in 1 (Dell) and it only reports "open/close". However, when computer goes tablet or tent mode there is a keystroke reported to disable keyboard, hence, a combination of accel, keystroke and lid "open/close" can tell if the computer is in tablet/tent mode. Commented Apr 25, 2017 at 12:37
  • 1
    This work on Linux too, however, with a slight modification: LID instead of LID0/proc/acpi/button/lid/LID/state. Commented Oct 6, 2022 at 12:39
2

Not really an answer to your linux-specific question, so maybe this answer should be moved to the comments:

MacBooks of all generations are known to have some issues with their system management controller of which one of the symptoms is strange behavior on lid-close and lid-open. This support page from Apple might help you resolve the problem: https://support.apple.com/kb/HT3964

1
  • BSD-style systems usually have a sysctl value that indicates whether the lid is open or closed. sysctl | grep lid would yield the name of the sysctl you want. However, I don't know about the way Linux handles this. Commented Aug 3, 2014 at 23:19

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.