Monday, November 02, 2015

How to detect Macbook open and close lid

I find this useful when tracing the time I spent in the computer or when I opened/closed my computer.

Find when you opened the lid:

$ tail -n 1000 /var/log/system.log | grep "Wake reason: EC.LidOpen (User)"

  • Replace 1000 with the number of lines you wish to backtrack
  • system.log might have already logrotated. gunzip if the past logs are already rotated:

$ ls /var/log/system.log*

Example: $ gunzip /var/log/system.log.0.gz

Find when you closed the lid:

$ tail -n 1000 /var/log/system.log | grep "messageType = 0xE0000280"

Example line:

Nov  1 15:37:07 My-MacBook-Pro kernel[0]: AppleCamIn::systemWakeCall - messageType = 0xE0000280