Last active
June 25, 2026 20:05
-
-
Save armanddp/1ddf5e5202613672cfc97ae9cafa344a to your computer and use it in GitHub Desktop.
Stay Awake
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
| # 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