Keep your Mac awake during a long build or render
A clean build, a video export, a Blender render — the kind of job you start and step away from for coffee. Come back to find the Mac asleep and the job frozen where it stood, and you've lost twenty minutes for nothing. The reliable fix is to run the job through caffeinate: it keeps the machine awake for exactly as long as the work runs, then lets go automatically.
Run the job under caffeinate
Instead of asserting wakefulness separately and hoping the timing lines up, hand your build command straight to caffeinate. It holds off idle sleep while the command runs and releases the moment it exits — success or failure.
# Xcode build, awake until it finishes
caffeinate -i xcodebuild -scheme MyApp
# A Makefile target
caffeinate -i make release
# An ffmpeg export
caffeinate -i ffmpeg -i in.mov -c:v prores out.mov
The -i flag stops idle system sleep, so the CPU and GPU keep grinding. The display is still allowed to sleep — the render doesn't care whether the screen is on, and letting it darken keeps the machine cooler and quieter. No timer to guess, and nothing left asserting once the build is done.
Attach to an export that's already running
The build's been going for ten minutes in an app like Final Cut or Compressor before you remember about sleep — no need to cancel and restart. Point caffeinate at the running process and it waits for that specific job to exit with -w.
# Find the render process id
pgrep -fl Compressor
# Keep awake until that process exits
caffeinate -i -w 5120
The -w flag takes a process ID and holds the assertion until that PID is gone. It's the rescue move for a job you didn't launch from the command line — grab its PID with pgrep or Activity Monitor, and caffeinate babysits it to the end.
Make it automatic for every build
If long builds are a daily thing, stop remembering to type caffeinate at all. Add a shell alias so a single word wraps whatever you run.
# Add to ~/.zshrc, then: awake make release
alias awake='caffeinate -i'
Now awake make release or awake npm run build keeps the Mac up for the duration of any command you prefix. It's a small habit that quietly removes a whole category of "why did that fail overnight" mysteries.
What to know before you rely on it
- There's no
defaultskey. caffeinate is the supported tool; the alternative is raising the coarse sleep timers under Battery and Lock Screen in System Settings, which changes your Mac's behaviour all the time rather than for one render. - Some apps already assert. Final Cut Pro and a few pro tools hold their own no-sleep assertion during export, but plenty of tools — command-line renderers, older apps, batch scripts — don't. When in doubt, wrapping in caffeinate is harmless and guarantees it.
- On battery, prefer
-i. The heavier-sflag only works on AC power; for a long render you'll want to be plugged in anyway, and-ibehaves identically whether you are or not.
If the Terminal isn't where you live, Mainspring's Keep Awake power-up runs caffeinate for a duration you choose and expires on its own when the render's done — part of 90+ hidden macOS settings it turns into labelled, reversible toggles.
Try Mainspring free →Signed & notarized by Apple · 1-day free trial · $29 once
Tidy up that alias while you're in there
Adding the awake alias is a good excuse to clean up your shell config. Our guide to customizing your .zshrc on Mac covers aliases, functions, and prompt tweaks that make long-running work smoother.