Skip to content

What is caffeinate MacOS command?

The MacOS caffeinate command is a useful tool that prevents your system from sleeping, putting displays to sleep, or enabling automatic sleep. By using this command, you can keep your Mac awake for a specified period of time, ensuring uninterrupted tasks and processes. This feature is particularly handy when you need to prevent your computer from entering sleep mode during long-running tasks or presentations.

caffeinate Syntax:

Terminal window
caffeinate [options]

caffeinate Options:

OptionDescription
-dPrevent the display from sleeping
-iKeep the system running even if idle
-mPrevent the disk from entering sleep mode
-sPrevent the system from sleeping
-uMake the command exit when the user is inactive
-t Specify a timeout in seconds for the command
-h, -?, -helpDisplay help information

Parameters:

ParameterDescription
secondsOptional. Specify the number of seconds to run the caffeinate command before it exits automatically. Use with the -t option.

caffeinate Command Usage Examples:

Prevent Mac from Sleeping for 1 Hour

Terminal window
caffeinate -u -t 3600

Prevents the Mac from going to sleep for 1 hour.

Keep Mac Awake Until a Specific Command is Completed

Terminal window
caffeinate -s command

Keeps the Mac awake until the specific command is completed.

Prevent Display from Dimming

Terminal window
caffeinate -d

Prevents the display from dimming on the Mac.

Prevent Mac from Sleeping Indefinitely

Terminal window
caffeinate -s

Prevents the Mac from going to sleep indefinitely until interrupted.

Prevent Disk from Spinning Down

Terminal window
caffeinate -m

Prevents the disk from spinning down on the Mac.

How do I use caffeinate in MacOS?

To use the caffeinate command in bash, execute the following command:

Terminal window
caffeinate

What are the common options available with caffeinate?

To specify options with caffeinate, you can use flags like -d (prevent the display from sleeping), -i (prevent the system from idle sleeping), and -u (prevent the system from going to sleep).

Terminal window
caffeinate -u

How can I prevent the system from idle sleeping using caffeinate?

To prevent the system from idle sleeping using caffeinate, you can use the -i option. Here is an example:

Terminal window
caffeinate -i

How do I specify a custom time for caffeinate to run?

To run caffeinate for a specific amount of time, you can specify the duration in seconds using the -t option. For instance:

Terminal window
caffeinate -t 3600

Can I prevent the disk from entering sleep mode using caffeinate?

Yes, you can prevent the disk from entering sleep mode by using the -m option with caffeinate. Here is an example:

Terminal window
caffeinate -m

How can I prevent the system from sleeping when using caffeinate?

To prevent the system from sleeping while using caffeinate, you can use the -s option. For example:

Terminal window
caffeinate -s

Is there a way to prevent the system from sleeping until a specific process is complete?

Yes, you can prevent the system from sleeping until a specific process is complete by using the -w option followed by the process ID. Here is how you can do it:

Terminal window
caffeinate -w <process_id>

How can I check the manual page for caffeinate?

To view the manual page for the caffeinate command, you can use the man command in the terminal. Here is an example:

Terminal window
man caffeinate

Applications of the caffeinate command

  • Preventing the Mac from going to sleep
  • Keeping the display on
  • Preventing the hard drive from going to sleep
  • Running specific tasks that should not be interrupted by system sleep