16

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.

Naftuli Kay
  • 38,686
  • 85
  • 220
  • 311

2 Answers2

24

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.

Naftuli Kay
  • 38,686
  • 85
  • 220
  • 311
  • To note: this works on my MacBook Pro, a Dell laptop, and a Gateway laptop also, so I'm assuming this is fairly ubiquitous. – Naftuli Kay Aug 06 '14 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? – JrBenito Apr 24 '17 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. – JrBenito Apr 25 '17 at 12:37
  • This work on Linux too, however, with a slight modification: `LID` instead of `LID0` → `/proc/acpi/button/lid/LID/state`. – tukusejssirs Oct 06 '22 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

user79620
  • 21
  • 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. – user79620 Aug 03 '14 at 23:19