4

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.

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.

2 Answers2

2

I'm assuming this problem has been resolved by now, (11 years, 7 months later...) But I had the same question, and found the solution on SO here, and I thought I would post it for others looking for a solution:

ioreg -r -k AppleClamshellState -d 4 | grep AppleClamshellState | head -1

echoes

  • | "AppleClamshellState" = Yes when lid is closed and
  • | "AppleClamshellState" = No when lid is not closed

You can turn it into a boolean expression with

if [[ $(ioreg -r -k AppleClamshellState -d 4 | grep AppleClamshellState  | head -1 | grep "Yes" -c) -eq 1 ]]; then
  (...)
fi

Tried and tested on a MBP 2023 M3 Pro running Mac OS Sonoma 14.6.1

Klumpy7
  • 121
0

I use Caffine to keep my Mac awake. You can set it for a specific time period. Then have it stop, or shut down your computer.

bret7600
  • 217
  • 3
  • 10