Skip to content

vcode11/stay-awake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

stay-awake

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.

Why

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.

Install

curl -o /usr/local/bin/stay-awake https://raw.githubusercontent.com/vcode11/stay-awake/main/stay-awake
chmod +x /usr/local/bin/stay-awake

Or clone and symlink into your ~/bin:

git clone https://github.com/vcode11/stay-awake.git
ln -s "$PWD/stay-awake/stay-awake" ~/bin/stay-awake

Usage

stay-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 finishes

Any extra arguments are passed straight through to caffeinate.

How it works

  • 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), a trap restores lid-close sleep with pmset -a disablesleep 0

The cleanup runs exactly once and is idempotent, so your machine always returns to normal sleep behavior when the script stops.

Requirements

  • macOS
  • sudo access (for pmset disablesleep)

License

MIT

About

Keep your Mac awake — even with the lid closed — for long-running agents and jobs.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages