To temporarily prevent a Mac from sleeping, use the caffeinate command in Terminal, or adjust the Energy Saver/Battery settings for a set duration. The quickest one-time fix is caffeinate -u -t 3600, which keeps the Mac awake for one hour; for a permanent change, set the display and system sleep timers to “Never” in System Settings.
Why Macs Sleep and What “Temporary” Means
macOS puts the Mac to sleep to save power and protect the display. By default, the system sleeps after a period of inactivity, and the display turns off sooner. “Temporarily” can mean anything from a few minutes to a few hours, or until you manually wake it. The right method depends on whether you need the screen on (for a presentation) or just the system running (for a download or render).
Method 1: The caffeinate Command (Terminal)
The caffeinate command is built into macOS and is the most flexible temporary option. It prevents the system from sleeping for a specified time or until you stop it.
- Open Terminal (Finder → Applications → Utilities → Terminal).
- Type
caffeinate -u -t 300and press Return. This keeps the Mac awake for 300 seconds (5 minutes). The-uflag also simulates user activity, so the display stays on. - To run it indefinitely until you press Ctrl+C, use
caffeinatealone. - To keep the system awake but allow the display to sleep, omit the
-uflag:caffeinate -t 300.
You can also combine it with a command, e.g., caffeinate -i make build to keep the Mac awake during a long compile. The -i flag prevents idle sleep.
Method 2: System Settings (Energy Saver / Battery)
For a temporary but scheduled change, use the graphical settings:
- Open System Settings (Apple menu → System Settings).
- Click Battery (or Energy Saver on older macOS).
- Set “Turn display off on battery when inactive” and “Turn display off on power adapter when inactive” to Never.
- Also set “Prevent automatic sleeping on power adapter when the display is off” to Always (this option is on some models).
This is temporary only if you remember to change it back. For a timed session, use the pmset command instead: sudo pmset -a sleep 0 disables sleep, and sudo pmset -a sleep 10 restores a 10-minute timer. Requires admin password.
Method 3: Third-Party Apps (Amphetamine, KeepingYouAwake)
These free apps add a menu bar icon that toggles sleep prevention with one click. Amphetamine offers a timer, triggers (e.g., when a specific app opens), and can keep the display on or off. KeepingYouAwake is simpler. They are safe and widely used, but they are not necessary if the built-in tools suffice.
How to Choose the Right Method
- One-time, short duration (minutes):
caffeinate -u -t 300 - One-time, long duration (hours):
caffeinate -u -t 10800(3 hours) or use Amphetamine with a timer. - While running a specific command:
caffeinate -i your-command - For a presentation or video playback: Use
caffeinate -uto keep the display on. - For a download or render:
caffeinate -s(prevents idle sleep, allows display sleep) or justcaffeinate.
Common Problems and Fixes
Problem: The Mac still sleeps despite caffeinate. Fix: Check if you used -u (keeps display awake) vs -i (keeps system awake). Also, some clamshell modes (lid closed) may override caffeinate unless you have an external display and power.
Problem: The display turns off but the system stays awake. Fix: That is normal if you did not use -u. Use -u to keep the display on.
Problem: caffeinate stops after a few minutes. Fix: You may have set a timer with -t. Run without -t for indefinite.
Safety and Battery Considerations
Keeping a Mac awake for long periods is generally safe, but it uses more power. On a laptop, expect significantly shorter battery life. Overheating is rare but possible if the Mac is in a hot environment or covered. For extended sessions, use a hard surface and consider removing a thick case. Also, macOS may still perform scheduled maintenance (like backups) while awake, which is fine.
Alternatives to Preventing Sleep
If your goal is to keep a process running (e.g., a download), you can also use Power Nap (if supported) to allow background activity while sleeping. For presentations, you can use Keynote's "Play Slideshow" which disables sleep. For video playback, some apps (like VLC) have a "prevent sleep" option. The pmset command can also set a sleep timer for a specific time, e.g., sudo pmset repeat sleep MTWRF 22:00:00 to sleep at 10 PM on weekdays.
Frequently Asked Questions
Q: Does caffeinate work when the lid is closed?
On a MacBook, closing the lid forces sleep unless you have an external display and power connected, or use a tool like Amphetamine with "Allow closed-display mode" enabled. caffeinate alone does not override lid-closed sleep.
Q: How do I stop caffeinate after it starts?
Press Ctrl+C in the Terminal window where it is running. If you closed the terminal, use Activity Monitor to quit the process named "caffeinate".
Q: Is it safe to leave my Mac on all night?
Yes, it is safe. Modern Macs manage heat and power well. The main downside is electricity use and potential screen burn-in on OLED displays if left static for days, but overnight is fine.
Q: Why does my Mac still sleep after I set "Never" in System Settings?
Check if you set both "on battery" and "on power adapter" to Never. Also, some macOS versions have a separate "Prevent automatic sleeping" checkbox that must be enabled. If you used caffeinate, it only lasts until the terminal session ends.
Q: Can I schedule sleep prevention for a specific time?
Yes, use pmset repeat sleep TWRF 23:00:00 to set a weekly schedule, but this is a permanent schedule. For a one-time timed session, use caffeinate with -t or an app like Amphetamine with a timer.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Google Assistant IFTTT Recipes: 7 Useful Automations
- OLED TVs in Dark Rooms: Why They Look Better and When They Don’t
- Philips DST7060/20 7000 Series Iron: Specs & Fit
- Coal Fueled Jet Aircraft: Could It Work?675 L
- Remote Desktop on Raspberry Pi: How to Enable It
- Word Select Last Line in Paragraph?