Skip to content

Instantly share code, notes, and snippets.

@rtanikella
Created December 17, 2022 15:24
Show Gist options
  • Save rtanikella/7d695a6aace24cf362ee6a1b69320182 to your computer and use it in GitHub Desktop.
Save rtanikella/7d695a6aace24cf362ee6a1b69320182 to your computer and use it in GitHub Desktop.
A shell script to list events in the macOS to list out sleep and wake events. This might be out-of-date with current versions of macOS (Monterrey/12.6.1)
#!/bin/sh
log show --last 24h | grep -e "System Sleep" -e " Wake reason" > /tmp/sleep-wake-hist.txt
pmset -g log | grep -e " Sleep " -e " Wake " >> /tmp/sleep-wake-hist.txt
sort -o /tmp/sleep-wake-hist-sorted.txt /tmp/sleep-wake-hist.txt
echo -n `wc -l /tmp/sleep-wake-hist-sorted.txt` log lines found
cat /tmp/sleep-wake-hist-sorted.txt
@rtanikella
Copy link
Author

HInts to myself for improvement:
Log lines like this one might indicate the closing of the laptop lid: '[HID] [ATC] AppleDeviceManagementHIDEventService::processWakeReason Wake reason: Keyboard (0x02)
2022-12-17 00:27:21 -0500 Sleep Entering Sleep state due to 'Clamshell Sleep':TCPKeepAlive=active Using Batt
(Charge:74%)'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment