Keep your Mac awake — even with the lid closed — for as long as you need. Built for the era of long-running agents and background jobs that must not get interrupted by a sleeping laptop.
Simple, effective, no dependencies beyond what macOS already ships.
macOS's built-in caffeinate keeps the display and system awake, but the Mac still sleeps when you close the lid. stay-awake combines caffeinate with pmset disablesleep so a closed-lid Mac keeps running your agent, build, or download — then cleanly restores normal sleep behavior when you stop it.
curl -o /usr/local/bin/stay-awake https://raw.githubusercontent.com/vcode11/stay-awake/main/stay-awake
chmod +x /usr/local/bin/stay-awakeOr clone and symlink into your ~/bin:
git clone https://github.com/vcode11/stay-awake.git
ln -s "$PWD/stay-awake/stay-awake" ~/bin/stay-awakestay-awake # stay awake until Ctrl+C
stay-awake -t 3600 # stay awake for 1 hour, then auto-restore
stay-awake ./long-job # stay awake until the command finishesAny extra arguments are passed straight through to caffeinate.
sudo pmset -a disablesleep 1— disables lid-close sleep (needs sudo)caffeinate -dis— prevents display, idle, and system sleep- On exit (Ctrl+C,
SIGTERM, or command completion), atraprestores lid-close sleep withpmset -a disablesleep 0
The cleanup runs exactly once and is idempotent, so your machine always returns to normal sleep behavior when the script stops.
- macOS
sudoaccess (forpmset disablesleep)
MIT