Skip to content

Instantly share code, notes, and snippets.

@armanddp
Last active June 25, 2026 20:05
Show Gist options
  • Select an option

  • Save armanddp/1ddf5e5202613672cfc97ae9cafa344a to your computer and use it in GitHub Desktop.

Select an option

Save armanddp/1ddf5e5202613672cfc97ae9cafa344a to your computer and use it in GitHub Desktop.
Stay Awake
# Keep the Mac awake with the lid closed. Requires sudo because this toggles
# the system-wide pmset SleepDisabled flag.
mac-lid-awake-on() {
sudo pmset -a disablesleep 1
mac-lid-awake-status
}
mac-lid-awake-off() {
sudo pmset -a disablesleep 0
mac-lid-awake-status
}
mac-lid-awake-status() {
local state
state=$(ioreg -r -c IOPMrootDomain | awk -F'= ' '/"SleepDisabled"/ {gsub(/[ "]/, "", $2); print $2; exit}')
case "$state" in
Yes) echo "Lid-closed sleep is disabled: this Mac should stay awake when closed." ;;
No) echo "Lid-closed sleep is enabled: this Mac may sleep when closed." ;;
*) echo "Could not read SleepDisabled state." ;;
esac
pmset -g | awk '/ sleep / || /disablesleep/ {print}'
}
alias lidawake='mac-lid-awake-on'
alias lidsleep='mac-lid-awake-off'
alias lidstatus='mac-lid-awake-status'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment