A tiny macOS shell script (with TUI available) for toggling system sleep with pmset.
It is intended for cases where you need a system-level sleep toggle, including lid-closed use, rather than a temporary per-process keep-awake command.
NoSleep ships in three flavors — pick whichever feels most comfortable:
| Interface | Best for | How to run |
|---|---|---|
Bash script (cli/nosleep.sh) |
Minimalists who like one-liners and shell history | ./cli/nosleep.sh on |
| TUI dashboard | People who want a keyboard-driven visual interface | ./cmd/nosleep-tui/nosleep-tui |
macOS app (NoSleep.app) |
Anyone who wants a regular double-clickable Mac app | make app, then copy to /Applications |
All three call into the same nosleep.sh under the hood — the TUI and the app just embed it for convenience, so behavior is identical across them. Pick whichever fits your workflow.
chmod +x cli/nosleep.sh
./cli/nosleep.sh on
./cli/nosleep.sh off
./cli/nosleep.sh status
./cli/nosleep.sh setup
./cli/nosleep.sh helponrunssudo pmset -a disablesleep 1offrunssudo pmset -a disablesleep 0statusreads the currentdisablesleepvalue frompmsetsetupinstalls a sudoers rule soon/offstop asking for a passwordhelpshows the usage message
All commands accept --json for machine-readable output:
./cli/nosleep.sh status --json # {"state":"awake","disablesleep":1}
./cli/nosleep.sh on --json # {"ok":true,"action":"on"}
./cli/nosleep.sh off --json # {"ok":true,"action":"off"}
./cli/nosleep.sh setup --json # {"ok":true,"action":"setup","user":"yourname"}- Running a long local job or server while the Mac is closed and away from a charger.
- Allowing longer-running work such as app builds, model training, or other compute-heavy tasks to continue while you are in transit or moving between meetings.
- Keeping a remote session, file transfer, or other background task alive when normal sleep would interrupt it.
- Temporarily preventing sleep on a machine used as a small home server, lab machine, or automation host.
- Using a Mac in a setup where
caffeinateis not sufficient and you intentionally need sleep disabled at the system level.
caffeinate is commonly used to keep a Mac awake while a process is running or while the display remains open, but it does not change the underlying system sleep setting in the same way.
This script uses pmset to change the system disablesleep setting directly. In practice, that means it can continue preventing sleep in situations where caffeinate is not the right tool, including lid-closed use and operation on battery power without a charger connected.
- This changes a system-level power setting, not just a single terminal session.
- If left enabled, your Mac can remain awake with the lid fully closed and while not connected to power.
- This can increase battery drain and may cause the laptop to become hot, especially if it is placed in a bag or another poorly ventilated space.
- Use it only when you intentionally need this behavior, and run
offas soon as you are done.
- macOS only
onandoffusesudo, so they may prompt for an administrator password- running the script with no arguments shows the usage message
-aapplies the setting to all power profiles
If you want to call it as nosleep from anywhere:
chmod +x cli/nosleep.sh
sudo ln -s "$(pwd)/cli/nosleep.sh" /usr/local/bin/nosleepThis requires administrator access because /usr/local/bin is a system directory.
Apple Silicon note: On Apple Silicon Macs,
/usr/local/binmay not be in your$PATH(Homebrew uses/opt/homebrew/binby default). You can either add/usr/local/binto yourPATH, or symlink into/opt/homebrew/bininstead.
The easiest way:
./cli/nosleep.sh setupThis creates a sudoers drop-in file for the current user. You'll enter your password once during setup — after that, on and off work without prompting.
You can also do it manually for a single user or an entire group:
# Allow all admin-group users to run pmset without password
echo "%admin ALL=(ALL) NOPASSWD: /usr/bin/pmset -a disablesleep 0, /usr/bin/pmset -a disablesleep 1" | sudo tee /etc/sudoers.d/nosleepOr limit it to a single user:
echo "yourusername ALL=(ALL) NOPASSWD: /usr/bin/pmset -a disablesleep 0, /usr/bin/pmset -a disablesleep 1" | sudo tee /etc/sudoers.d/nosleepThis creates a drop-in file under /etc/sudoers.d/, which is safer than editing /etc/sudoers directly. The status command does not use sudo, so it is unaffected.
Releases are automatically built and published to GitHub Releases when a new tag is pushed. The workflow builds both the TUI binary and the macOS app bundle.
To create a new release:
- Create and push a new tag:
git tag v1.2.3 - Push the tag:
git push origin v1.2.3 - GitHub Actions will automatically build and create a release with assets
A terminal UI dashboard for toggling sleep with keyboard shortcuts. The TUI communicates with nosleep.sh via the --json flag for structured, reliable parsing.
The easiest way to build the TUI is using make:
make buildThis will automatically generate the required embedded files and compile a single, self-contained nosleep-tui binary in cmd/nosleep-tui/.
Prerequisites: Go 1.16+ (required for go:embed). Install via go.dev/dl or brew install go.
You can run it directly, use the macOS launcher, or use the make target:
./cmd/nosleep-tui/nosleep-tui
# or double-click mac/nosleep.command
# or
make run| Key | Action |
|---|---|
| Space | Toggle sleep on/off |
| s | Setup passwordless mode |
| h | Open help |
| esc | Close help / Quit |
| r | Refresh status |
| q | Quit |
First time? Press
sto install the passwordless sudoers rule — otherwiseSpacewill prompt for your password each time you toggle.
You can build a NoSleep.app bundle that works like a regular Mac app — double-click to launch, shows up in Spotlight and Launchpad.
make appThis produces build/NoSleep.app. To install, copy it to /Applications:
cp -r build/NoSleep.app /Applications/Per-user install: If you don't want to copy to the system-wide
/Applications(which requires admin), you can copy it to~/Applicationsinstead — macOS will still pick it up for Launchpad and Spotlight. Create the folder first withmkdir -p ~/Applicationsif it doesn't exist.
The app opens Terminal.app and runs the TUI inside it. The binary is fully self-contained — no external files or repo checkout needed.
Gatekeeper note: The bundle is ad-hoc signed, which works on the machine that built it. On other machines, macOS may block the app on first launch. To allow it, run:
xattr -cr NoSleep.app