Instantly share code, notes, and snippets.

Embed
What would you like to do?
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/)
#!/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