<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/macos-use-caffeinate-to-keep-your-computer-on-gnqwpxr5c" -->

---
title: macOS: use caffeinate to keep your computer on | daily.dev
description: Explains how to use the built-in macOS caffeinate command, available since OS X Mountain Lion (2012), to prevent a Mac from sleeping during long-running jobs....
canonical: https://daily.dev/posts/macos-use-caffeinate-to-keep-your-computer-on-gnqwpxr5c
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: macOS: use caffeinate to keep your computer on | daily.dev
og:description: Explains how to use the built-in macOS caffeinate command, available since OS X Mountain Lion (2012), to prevent a Mac from sleeping during long-running jobs....
og:url: https://daily.dev/posts/macos-use-caffeinate-to-keep-your-computer-on-gnqwpxr5c
og:image: https://api.daily.dev/og/posts/gNqWpXR5c.png
og:image:alt: macOS: use caffeinate to keep your computer on
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# macOS: use caffeinate to keep your computer on

**[Adam Johnson](https://daily.dev/sources/adamj)** · 3 min read · 0 upvotes · 0 comments

## Summary

Explains how to use the built-in macOS caffeinate command, available since OS X Mountain Lion (2012), to prevent a Mac from sleeping during long-running jobs. Covers wrapping a command with caffeinate, running it bare and interrupting with Ctrl-C, attaching it to an already-running process with -w and a PID (found via Ctrl-Z/fg or pgrep), and using -d alongside -i to also keep the display on. Notes caffeinate cannot prevent sleep triggered by closing the laptop lid, though the job keeps running behind a locked screen.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://adamj.eu/tech/2026/09/20/macos-caffeinate>

## Questions this post answers

### How do I keep my Mac awake while running a long command in the terminal?

Wrap the command with the built-in caffeinate utility, for example `caffeinate ./migrate.sh`, and it keeps the machine awake for the duration of the command, letting sleep resume once it finishes. Running caffeinate alone holds the machine awake until interrupted with Ctrl-C, useful for a quick fix before stepping away.

_daily.dev surfaces practical command-line tips like this for developers automating their macOS workflow._

### How can I prevent sleep for a process that's already running on macOS without restarting it?

Use `caffeinate -w <PID>` to keep the machine awake until the specified process ID exits. Find the PID with Activity Monitor or pgrep, or by suspending the job with Ctrl-Z in the shell, resuming it with a job control command like %1, noting the PID shown, then running caffeinate in a second terminal tab.

_developers juggling long background jobs can keep tracking macOS workflow tricks on daily.dev._

### Does caffeinate keep the display on or prevent the laptop lid from triggering sleep?

By default caffeinate only prevents idle sleep, not display sleep; add the -d option combined with -i (as `caffeinate -id`) to also keep the display from dimming or turning off. It cannot override the lid switch, so closing a laptop lid still forces sleep regardless of caffeinate running.

_anyone relying on caffeinate for uninterrupted jobs can find more macOS command-line know-how on daily.dev._

## Similar posts on daily.dev

- [Open Caffeine: Keep your Mac awake](https://daily.dev/posts/open-caffeine-keep-your-mac-awake-rtwuusbe3) · Product Hunt · 69 upvotes · 20 comments

---

Tags: [#cli](https://daily.dev/tags/cli), [#mac](https://daily.dev/tags/mac), [#bash](https://daily.dev/tags/bash)

[View this post on daily.dev](https://daily.dev/posts/macos-use-caffeinate-to-keep-your-computer-on-gnqwpxr5c)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"macOS: use caffeinate to keep your computer on","url":"https://daily.dev/posts/macos-use-caffeinate-to-keep-your-computer-on-gnqwpxr5c","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/macos-use-caffeinate-to-keep-your-computer-on-gnqwpxr5c"},"datePublished":"2026-09-20T22:13:30.196Z","dateModified":"2026-09-20T22:13:52.900Z","description":"Explains how to use the built-in macOS caffeinate command, available since OS X Mountain Lion (2012), to prevent a Mac from sleeping during long-running jobs....","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4189005ccd52da91dab54a58529023ee?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4189005ccd52da91dab54a58529023ee?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Adam Johnson","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Adam Johnson","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/bf70f4401c284aa5b628d1966029342c","url":"https://daily.dev/sources/adamj"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/macos-use-caffeinate-to-keep-your-computer-on-gnqwpxr5c","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"cli,mac,bash","timeRequired":"PT3M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Adam Johnson","item":"https://daily.dev/sources/adamj"},{"@type":"ListItem","position":3,"name":"macOS: use caffeinate to keep your computer on"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/macos-use-caffeinate-to-keep-your-computer-on-gnqwpxr5c#faq","mainEntity":[{"@type":"Question","name":"How do I keep my Mac awake while running a long command in the terminal?","acceptedAnswer":{"@type":"Answer","text":"Wrap the command with the built-in caffeinate utility, for example `caffeinate ./migrate.sh`, and it keeps the machine awake for the duration of the command, letting sleep resume once it finishes. Running caffeinate alone holds the machine awake until interrupted with Ctrl-C, useful for a quick fix before stepping away. daily.dev surfaces practical command-line tips like this for developers automating their macOS workflow."}},{"@type":"Question","name":"How can I prevent sleep for a process that's already running on macOS without restarting it?","acceptedAnswer":{"@type":"Answer","text":"Use `caffeinate -w \u003cPID\u003e` to keep the machine awake until the specified process ID exits. Find the PID with Activity Monitor or pgrep, or by suspending the job with Ctrl-Z in the shell, resuming it with a job control command like %1, noting the PID shown, then running caffeinate in a second terminal tab. developers juggling long background jobs can keep tracking macOS workflow tricks on daily.dev."}},{"@type":"Question","name":"Does caffeinate keep the display on or prevent the laptop lid from triggering sleep?","acceptedAnswer":{"@type":"Answer","text":"By default caffeinate only prevents idle sleep, not display sleep; add the -d option combined with -i (as `caffeinate -id`) to also keep the display from dimming or turning off. It cannot override the lid switch, so closing a laptop lid still forces sleep regardless of caffeinate running. anyone relying on caffeinate for uninterrupted jobs can find more macOS command-line know-how on daily.dev."}}]}
```

