Sometimes you want your Macbook/MacOS to stay on, while you go to other things. And let's face it - it's very annoying to come back to a locked machine that might have stopped your process at the same time.

How Do I Keep My Mac Awake?

Simple, really. You can use the built-in `caffeinate` command to prevent your Mac from sleeping. Run the following in your terminal:
caffeinate -di

What Do The Parameters Mean?

  • -d Prevent the display from sleeping.
  • -i Prevent the system from idle sleeping.
  • -m Prevent the disk from idle sleeping.
  • -s Prevent the system from sleeping. Can only be used when running on AC power.
  • -u Tells the system that the user is active. If the display is off, it will turn the display on and keep it from going to sleep. If you don't specify a timeout using -t, it will stay active for 5 seconds by default.
  • -t timeout Sets how long (in seconds) the assertion should remain active. After the specified time passes, the assertion is automatically removed. This timeout does not apply if you run a utility with the command.
  • -w pid Waits for the process with the specified process ID (PID) to finish. When that process exits, the assertion is automatically released. This option is ignored if you use the utility option.

Example Usage

To keep your Mac awake for 1 hour, you can run:
caffeinate -di -t 3600
This command will prevent both the display and the system from sleeping for 3600 seconds (1 hour). To keep your Mac awake while a specific process is running, you can use:
caffeinate -di -w PID
PID should be replaced with the actual process ID of the application you want to keep awake. You can find the PID using commands like `ps` or `top`.