Created
May 13, 2026 02:21
-
-
Save dr2050/485872c73289598aecb396a8969bc99a to your computer and use it in GitHub Desktop.
[Mac Utility] Allow Mac to continue grinding while the lid is closed
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/zsh | |
| set -euo pipefail | |
| SCRIPT_NAME="$(basename "$0")" | |
| usage() { | |
| cat <<EOF | |
| Usage: | |
| sudo $SCRIPT_NAME start | |
| sudo $SCRIPT_NAME stop | |
| $SCRIPT_NAME status | |
| EOF | |
| } | |
| require_root() { | |
| if [[ "${EUID}" -ne 0 ]]; then | |
| echo "Please run with sudo:" | |
| echo " sudo $SCRIPT_NAME $1" | |
| exit 1 | |
| fi | |
| } | |
| status() { | |
| pmset -g | awk ' | |
| tolower($1) == "sleepdisabled" || tolower($1) == "disablesleep" { | |
| print "SleepDisabled = " $2 | |
| found = 1 | |
| } | |
| END { | |
| if (!found) { | |
| print "SleepDisabled setting not found in pmset output." > "/dev/stderr" | |
| exit 1 | |
| } | |
| } | |
| ' | |
| } | |
| start() { | |
| require_root start | |
| pmset disablesleep 1 | |
| echo "Closed-lid sleep disabled." | |
| status | |
| } | |
| stop() { | |
| require_root stop | |
| pmset disablesleep 0 | |
| echo "Normal sleep restored." | |
| status | |
| } | |
| case "${1:-}" in | |
| start) | |
| start | |
| ;; | |
| stop) | |
| stop | |
| ;; | |
| status) | |
| status | |
| ;; | |
| *) | |
| usage | |
| exit 1 | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment