Skip to content

Instantly share code, notes, and snippets.

@wdcurry
Created August 22, 2025 14:31
Show Gist options
  • Select an option

  • Save wdcurry/18d15a1266459decece3860f71e8aba5 to your computer and use it in GitHub Desktop.

Select an option

Save wdcurry/18d15a1266459decece3860f71e8aba5 to your computer and use it in GitHub Desktop.
Simple script to summarize your mac's logs for sleep/wake cycles over the last 7 days. VERY important if you travel with your laptop, and if you use a protective screen cover on it. You may be inadvertently causing undue stress to your beloved companion as the lid might not be shut tight.
#!/bin/bash
# Usage: ./checkLaptop.sh [days]
# createdy by drew curry, aug22-cv05
# ------
# Simple script to summarize your mac's logs for sleep/wake cycles over the last 7 days.
# VERY important if you travel with your laptop, and if you use a protective screen cover on it.
# You may be inadvertently causing undue stress to your beloved companion as the lid might not be shut tight.
# Don't forget to "chmod +x checkLaptop.sh" to make this executable, then "./checkLaptop.sh to run it (in the same folder)
# ------
DAYS=${1:-7}
pmset -g log --since "$(date -v-${DAYS}d '+%m/%d/%y 00:00:00')" \
| perl -ne 'if (/^(\d{4}-\d{2}-\d{2}).*\b(Wake|Sleep)\b(?!\/)/) { $c{$1}{$2}++ }
END { for $d (sort keys %c){ printf "%s Sleep %d Wake %d\n",$d,$c{$d}{Sleep}+0,$c{$d}{Wake}+0 } }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment