Skip to content

Instantly share code, notes, and snippets.

@semicolonsnet
Created March 13, 2022 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save semicolonsnet/ac2dc9050f55a531fcd08cc129e69849 to your computer and use it in GitHub Desktop.
Save semicolonsnet/ac2dc9050f55a531fcd08cc129e69849 to your computer and use it in GitHub Desktop.
Returns a non-zero error code if a macOS machine is asleep. Useful because Macs respond to pings when asleep, so you may need an alternative test.
#!/bin/bash
if [[ $(pmset -g powerstate | grep -E 'AppleDisplay') == "AppleDisplay 3 3 USEABLE" ]]
then
exit 0
else
exit 2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment