Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Shell script to display a notification if there are any processes preventing the system from sleeping 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:\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.