Caffeinate

Need a quick and painless way to keep your mac from going to lockscreen or screensaver?

Use caffeinate!

This became an issue where I wanted to run a script for work from my mac where I would continually query and restart a remote server. Due to work required software, I am unable to run it continually if I want to step away from the computer for a while, as the mandated screensaver would kick in, and would kill my fortinet vpn session, causing the script to basically timeout.

Enter Caffeinate.

As far as I can tell, it already comes pre installed on macOS. And running it is as simple as:

caffeinate -d

Simply put, this command prevents the display from sleeping.

You can see more information with this via tldr:

√ juuj@JJs-MacBook-Pro:~ % tldr caffeinate

caffeinate

Prevent macOS from sleeping.
More information: <https://keith.github.io/xcode-man-pages/caffeinate.8.html>.

- Prevent the display from sleeping:
    caffeinate -d

- Prevent from sleeping for 1 hour (3600 seconds):
    caffeinate -u -t 3600

- Fork a process, exec "make" in it, and prevent sleep as long as that process is running:
    caffeinate -i make

- Prevent from sleeping until a process with the specified PID completes:
    caffeinate -w pid

- Prevent disk from sleeping (use `<Ctrl c>` to exit):
    caffeinate -m