Check out Checkmango, the full-stack A/B testing platform.

TIL: macOS’ Hidden Gem – The "caffeinate" Command!

We’ve all heard of (or used) third-party applications like Caffeine to keep our Macs awake during long-running tasks. But did you know macOS has a built-in alternative? It’s called the caffeinate command, and it’s a nifty tool included right in your system.

What is the caffeinate Command?

The caffeinate command is a feature included in macOS that prevents the system from sleeping. You can find it in /usr/bin/caffeinate. It’s essentially a way to tell your Mac, "Hey, stay awake for a bit, I’ve got things to do!"

How Does It Work?

When you use caffeinate, it creates assertions that alter the system’s sleep behavior. By default, it prevents idle sleep, but you can customize its behaviour with various options:

  • -d: Prevents the display from sleeping.
  • -i: Prevents the system from idle sleeping.
  • -m: Keeps the disk awake.
  • -s: Stops the system from sleeping when connected to power.
  • -u: Declares user activity, turning the display on and preventing sleep (with a default 5-second timeout if not specified).

Practical Example

Let’s say you’re running a long build process — maybe you're still using Gulp 👀. You can use caffeinate -i npm run build, and your Mac won’t go to sleep until the process is complete. It’s simple yet incredibly effective.

Why Use caffeinate?

Using caffeinate means you no longer need to rely on third-party apps to keep your Mac awake. It’s a built-in, powerful tool that gives you control over your system’s sleep behavior, perfect for software developers or anyone running long tasks on their Mac.

So next time you need your Mac to stay awake for a bit, remember this hidden gem. And, remember to stay caffeinated ☕