How to set a sleep timer on your Mac
Falling asleep to a podcast, a movie, or a long render? macOS doesn't have a sleep timer in System Settings, but it has two ways to build one, and neither needs an app.
The short answer
Open Terminal and run sleep 1800; pmset sleepnow to sleep the Mac in 30 minutes; leave the window open. For a clock time, sudo shutdown -s 2330 sleeps it at 11:30 PM. Both work even while music or video is playing, which is exactly when the normal idle sleep doesn't.
1. In Terminal, in one line
sleep 1800; pmset sleepnow # sleep in 30 minutes (1800 seconds)
sleep 5400; pmset sleepnow # in 90 minutes
No admin password needed. Keep the Terminal window open until it fires; press Ctrl-C to cancel.
For a clock time, use shutdown, which on a Mac can sleep instead of shut down:
sudo shutdown -s 2330 # sleep at 11:30 PM
sudo shutdown -s +45 # sleep in 45 minutes
sudo killall shutdown # cancel
This one runs in the background, so you can close Terminal.
2. As a Shortcut you can click
- Open Shortcuts and create a new shortcut. Name it “Sleep timer.”
- Add Ask for Input, set to Number, with the prompt “Minutes?”
- Add Calculate to multiply the answer by 60, then Wait for that many seconds.
- Add Run Shell Script with
pmset sleepnow. The first time, Shortcuts asks you to allow running scripts in Settings › Advanced. - Pin it to the menu bar from the shortcut's details, or give it a keyboard shortcut.
3. Sleep when a job finishes, not after a guess
If you're waiting on a download, an export, or a script, don't guess at minutes. Chain the sleep after it:
./export.sh; pmset sleepnow
curl -O https://example.com/big.iso; pmset sleepnow
The Mac stays awake for the job and sleeps the moment it's done. If the job might outlast your idle timer, keep the Mac up for it too: caffeinate -i ./export.sh; pmset sleepnow, or with Midnight Oil's command, midnightoil run -- ./export.sh; pmset sleepnow.
Why the normal sleep setting doesn't help
System Settings' timers count idle time. Playing audio or video holds the Mac awake on purpose, so the idle timer never runs out while your podcast plays. A sleep timer works because pmset sleepnow is a direct request, like choosing Apple menu › Sleep. Where the regular settings live, and what each does, is in Mac sleep settings.
Questions
Does a Mac have a sleep timer?
Not in System Settings. Use Terminal: sleep 1800; pmset sleepnow sleeps the Mac in 30 minutes, and sudo shutdown -s 2330 sleeps it at 11:30 PM. A Shortcut with a Wait action and a Run Shell Script action does the same with a click.
Why doesn't my Mac sleep while music is playing?
Audio playback holds the Mac awake on purpose, so the normal idle timer never fires. pmset sleepnow is a direct sleep request, so a timer that ends with it works even with music or video playing.
How do I cancel a sleep timer?
For sleep 1800; pmset sleepnow, press Ctrl-C in that Terminal window. For sudo shutdown -s, run sudo killall shutdown.
Does shutdown -s turn my Mac off?
No. On macOS, shutdown -s means sleep. shutdown -h is the one that shuts down.
Can I make the Mac sleep after a download or render finishes?
Yes: put the command first and pmset sleepnow after it, like ./render.sh; pmset sleepnow. The Mac sleeps the moment the job ends.
More guides
Awake exactly as long as you need.
Free. No account, no subscription.
macOS 14 or later · Apple Silicon and Intel · brew install --cask coreyhaines31/tap/midnightoil