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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With