Stop Mac Sleeping When Specific Apps Are Running
In this article
You can stop a Mac from sleeping while specific apps are running by using the built-in caffeinate command with a process ID, or by pairing it with a small Automator or Shortcuts automation that launches when the app opens. macOS has no checkbox that says "keep awake for this app only," so the practical route is caffeinate tied to the app's process, or a third-party menu bar utility that watches for chosen apps. Both work; the command line method is free and needs no installs.
This is useful when a long render, download, backup, compile, or upload stalls because the Mac dims the display and then sleeps. Note that macOS labels can differ slightly by version, device, or region, so if a menu name below does not match exactly, look for the closest equivalent.
What You'll Need
- A Mac running a current version of macOS (Ventura or later is assumed for the Shortcuts steps; older versions can use Automator instead).
- Terminal, which is in Applications > Utilities.
- The exact name of the app you want to keep the Mac awake for, as it appears in Activity Monitor.
- Optional: a free menu bar utility from the Mac App Store if you prefer a graphical toggle over commands.
- Admin rights if you decide to change Energy Saver or Battery settings.
Step-by-Step
- Find the app's process name. Open Activity Monitor (Applications > Utilities), search for your app in the top-right search field, and note the name in the Process column. For most apps this is the app name, but some processes differ (for example, a helper process rather than the visible app).
- Test the command manually first. Open Terminal and run
caffeinate -w $(pgrep -x "AppName"), replacing AppName with the process name from step 1. If the app is running, Terminal will sit there silently and the Mac will not idle-sleep until the app quits. Press Control-C to stop it. - Understand what caffeinate does and does not do.
caffeinateprevents idle sleep. It does not stop the display from turning off unless you add-d, and it does not override a manual Sleep command or a lid close on a laptop. If you also want the screen to stay on, usecaffeinate -d -w $(pgrep -x "AppName"). - Automate it with Shortcuts. Open Shortcuts, create a new shortcut, and add a "Run Shell Script" action containing the caffeinate line above. Save it with a clear name such as "Keep Awake for Render." You can then run it from the menu bar, from a keyboard shortcut you assign in the shortcut's details, or from the Dock.
- Trigger it automatically when the app opens. In Shortcuts, open the shortcut's details and look for the automation or trigger options available in your macOS version. If your version does not offer an app-launch trigger, the reliable alternative is to launch the shortcut yourself right after opening the app, or to add the app to a login item set that runs the shortcut at startup.
- Or use a menu bar utility. Open the Mac App Store and search for a keep-awake utility that supports per-app rules. Install it from the App Store only, grant any permissions it asks for, then add your chosen app to its list of triggers. These utilities typically offer a toggle in the menu bar and an option to keep the display awake as well.
- Check your Energy settings so nothing fights you. Open System Settings > Lock Screen (or Energy Saver on older Macs) and note the "Turn display off after" and sleep timers. caffeinate overrides idle sleep, but a very short display-off timer can still make the screen go dark, which looks like sleep even when the Mac is awake.
- Verify it is working. With the command or utility active, leave the Mac idle for longer than your sleep timer. If the machine stays reachable (for example, a file share or remote session still responds), it is awake. You can also run
pmset -g assertionsin Terminal to see active assertions, including one created by caffeinate. - Stop it cleanly. If you used Terminal, press Control-C. If you used a shortcut, run the matching stop action or quit the Terminal window it opened. If you used a utility, toggle it off in the menu bar. Leaving caffeinate running indefinitely will drain a laptop battery.
Common Mistakes
- Using the wrong process name.
pgrep -xmatches the exact process name. If nothing happens, runpgrep -land look for the real name, then try again without-xif needed. - Expecting caffeinate to survive a closed lid. On a laptop, closing the lid sleeps the machine regardless. Keep the lid open or use clamshell mode with power and an external display.
- Confusing display sleep with system sleep. The screen going dark is not the same as the Mac sleeping. Add
-dif the display must stay lit. - Forgetting the battery. A caffeinate session with the display on can flatten a MacBook quickly. Use it on power when possible.
- Assuming the app quitting stops the command. It does with
-wand a valid PID, but if the app relaunches with a new PID the old command has already exited. Re-run the shortcut.
Tips
- Add
-ito prevent idle system sleep while still allowing the display to turn off, which saves power on long background jobs. - Add
-t 3600to cap the session at one hour as a safety net, so a forgotten command does not run all night. - Name your shortcuts clearly so they are easy to find in the menu bar and in Spotlight.
- If you run several long jobs, one caffeinate session with a time limit is easier to manage than several overlapping ones.
- Keep the utility or shortcut in the Dock for one-click access during heavy workloads.
Troubleshooting
The Mac still sleeps. Check that the command is actually running (Terminal window open, or the utility toggle on). Run pmset -g assertions and look for a caffeinate entry. If it is missing, the process name was wrong or the command exited immediately.
The command exits instantly. That means pgrep found no match. Confirm the app is open and the name is exact, including capitalization and spaces. Wrap names with spaces in quotes.
The screen turns off but the Mac stays awake. That is expected without -d. Add it if the display must remain on, and remember the power cost.
The shortcut does nothing. Open it in Shortcuts and run it manually to see the error. Shell script actions may need permission the first time; approve the prompt. If your macOS version lacks an app-launch trigger, run the shortcut manually after opening the app.
A utility stopped working after an update. Quit and reopen it, check for updates in the App Store, and re-grant any permissions it requests. If it still fails, remove and re-add your app rule.
Frequently Asked Questions
Is there a built-in setting for per-app sleep prevention?
No. macOS has no per-app sleep toggle. The supported approaches are the caffeinate command, an automation that runs it, or a third-party utility that watches for chosen apps.
Does caffeinate work when the lid is closed?
No. Closing the lid on a MacBook puts it to sleep. Keep the lid open, or use clamshell mode with power and an external display.
Will this stop a scheduled sleep or a manual Sleep command?
No. caffeinate blocks idle sleep. A manual Sleep from the Apple menu, a scheduled sleep event, or a low-battery sleep will still occur.
Does keeping the Mac awake damage it?
Not in itself. The main risks are battery drain on a laptop and heat if it is in a bag or poorly ventilated space. Use it on power and keep vents clear.
Can I keep the Mac awake for more than one app?
Yes. Run a separate caffeinate command per app, or use a utility that accepts multiple app rules. A single time-limited session is easier to manage.
Does this work on Apple silicon and Intel Macs?
Yes. caffeinate is part of macOS on both, and the menu paths are the same apart from minor version differences.