How to Check if Macbook Lid is closed via Terminal? [closed]
Asked Answered
O

1

9

I'm running OS X 10.8 (Mountain Lion). I was wondering if there was a terminal command to check if the macbook pro's lid is currently closed. If I used grep, what would I be looking for exactly, and where?

The reason I ask is because I have cron jobs scheduled to run every 30 minutes. However, crontab doesn't run when the computer is sleeping/hibernating. My solution was to use pmset to schedule wakes every 30 minutes. However, I need a way to put my computer back to sleep on the condition that the lid is currently closed. I don't want my computer to be awake for too long with the lid closed i.e. awake all night when I'm sleeping because that could damage the screen.

Offoffbroadway answered 7/4, 2013 at 21:44 Comment(0)
I
29
ioreg -r -k AppleClamshellState -d 4 | grep AppleClamshellState  | head -1

Tested and works on 10.7.*, found here.

Update 2019-02-26:

Still works on macOS 10.14.3 Mojave

Irritation answered 7/4, 2013 at 22:45 Comment(9)
No means open, Yes means closedCoycoyle
Also works on macos 10.14! I'm checking for closed state with that: ioreg -r -k AppleClamshellState -d 4 | grep AppleClamshellState | head -1 | grep Yes If i printed some text - the lid is closed. And vice versa.Gametophore
Also works on macos 10.15!Imaret
-d 1 is enough. (-d: Limit tree traversal to the specified depth.)Chummy
Also works on 10.15.7!Galloot
Also works on 11.2.3Headstall
Working on Ventura (macOS 13), Apple Silicon to boot!Continuation
To complete the list - it also works on macOS 12.7.3. ^^Irritation
Also works on Sonoma 14.3Baal

© 2022 - 2024 — McMap. All rights reserved.