How to check if the Macbook cover is closed through the terminal?

I am running OS X 10.8 (Mountain Lion). I was wondering if there is a terminal command to check if macbook pro lid is closed now. If I used grep, what would I look for exactly and where?

The reason I'm asking is because I have a cron job that should run every 30 minutes. However, crontab does not start when the computer is sleeping / asleep. My solution was to use pmset to plan wakeups every 30 minutes. However, I need my computer to sleep again, provided that the cover is currently closed. I don’t want my computer to wake up for too long with the lid closed, that is, sleep all night when I sleep, because it can damage the screen.

+5
source share
1 answer
ioreg -r -k AppleClamshellState -d 4 | grep AppleClamshellState  | head -1

Tested and working on 10.7. *, found here .

Update 2018-03-24:

Still working on macOS 10.13 High Sierra.

+10
source

All Articles