caffeinate command builder

Tick what you need, copy the command, paste it into Terminal. Nothing leaves your browser.

Updated · by Sasha Yakovlev, maker of Lidwork

Quick answer

Most people need caffeinate -i (no idle sleep until Control-C) or caffeinate -i your-command (awake exactly while it runs). Add -d to keep the screen on and -t 3600 for a one-hour limit. None of these keep a MacBook awake with the lid closed.

Prevent…
caffeinate -i
    Lid closed? caffeinate can't. These flags block idle sleep. Closing a MacBook's lid without an external display sleeps the Mac anyway — that's a separate sleep path that power assertions don't cover. The only built-in override is the pmset switch below, and it doesn't turn itself off. Why, in detail →

    pmset commands for the lid-closed case

    Copy these as they are. They need an administrator password.

    # disable all sleep, lid closed included (persistent!)
    sudo pmset -a disablesleep 1
    
    # check: 1 = sleep disabled, 0 = normal
    pmset -g | grep SleepDisabled
    
    # restore normal sleep — always run this afterwards
    sudo pmset -a disablesleep 0
    
    # what is keeping my Mac awake right now?
    pmset -g assertions

    If you'd rather not remember the last command, that's what Lidwork is for: it flips the switch from the menu bar and turns it back off on its own — when you toggle it, when the app crashes, and at your battery limit.

    How to use the command

    1. Open Terminal (Spotlight → “Terminal”).
    2. Paste the command and press Return.
    3. Leave the window open. Press Control-C to stop, or let the time limit / command end.