Created
December 25, 2018 05:37
-
-
Save yi-jiayu/f1a8f32d70a6a4c3b7dbd81589c40f0d to your computer and use it in GitHub Desktop.
Shell script to display a notification if there are any processes preventing the system from sleeping on macOS (https://blog.jiayu.co/2018/12/get-notified-when-a-process-is-preventing-sleep-on-macos/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh - | |
sleep_blocker=$(pmset -g | grep -m1 "sleep prevented by" | sed -E 's/.+sleep prevented by (.+)\)$/\1/') | |
if [ ! -z "$sleep_blocker" ]; then | |
osascript -e "display notification \"$sleep_blocker\" with title \"Sleep prevention warning\" subtitle \"The following processes are preventing sleep:\"" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment