I'm running archive utility on an iMac to extract thousands of files so it takes a long time. I will also be running a process in a program called R Studio that may take several days to complete. I need to find a way to keep the system from going to sleep and pausing these processes.

I believe the caffeinate command in terminal is the solution, but I am having trouble getting it to work they way I want it to.

I read the caffeinate man page and tried caffeinate -w [PID] which appeared to work as long as the display is on. Once the display turns off, the system pauses the process and goes to sleep anyway.

I also thought about trying caffeinate -s [utility] but per this webpage: http://osxdaily.com/2014/06/16/caffeinate-prevent-sleep-while-command-active-mac-os-x/ I need to specify the full path to the binary for the utility within the .app file and I'm not sure what that path is for either the extract process in Archive Utility or the process I'll be running in R Studio. Using the PID, which I can find in the Activity Monitor once the process has started, seemed more reliable.

I have read this related Q&A on superuser: Keep Mac running with display off However, I'm looking for a more targeted solution than what was suggested: caffeinate -s. My understanding is that the -s prevents the system from sleeping until caffeinate exits. I'd really like a solution that allows caffeinate to exit automatically when the process is done.

And I'm also really curious why the caffeinate -w assertion stops working when the display turns off.

NEW Q: My process finished its run but caffeinate didn't seem to exit as expected. What am I missing? and how do you terminate caffeinate other than quitting terminal? I've tried exit caffeinate but that didn't seem to do anything.


  • My last Mac Pro, bought in 2008, never slept in 10 years, it ran 24/7/365 rebooting only for OS updates until it finally gave up the ghost last year. What's wrong with 'computer sleep = never' in system prefs>energy saver?
    – Tetsujin
    Apr 27, 2019 at 16:33
  • That was my solution for my MacBook too. And when the process finished I changed the setting back. But I don't seem to have that option on the iMac. Also, I would really prefer to have it sleep when the process is finished. Seems caffeinate should do this, but I'm not getting expected behavior and want to know why.
    – ESELIA
    Apr 27, 2019 at 18:58

1 Answer 1


Have you tried caffeinate -d -w [PID]? That may work: -d Create an assertion to prevent the display from sleeping.

  • I wonder if that does keep the -w assertion working, but it is still odd that the -w only works when the display is running. I ended up just using the -s assertion and then putting my display to sleep manually so as not to waste additional power.
    – ESELIA
    Jul 29, 2020 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.