Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Prevent Mac Sleeping When Closing Lid

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide shows you how to keep your Mac awake when you close its lid, which is useful when using an external display, transferring large files, or running a server. You'll learn the built-in method using a terminal command, plus a few reliable alternatives. No additional software is strictly required, though a tool like Amphetamine (free on the App Store) can make the process easier for some users.

What You'll Need

  • A Mac running macOS (any recent version works).
  • An external power adapter (for most methods, the Mac must be plugged in).
  • An external display, keyboard, and mouse if you want to use the Mac while the lid is closed.
  • Optional: A free app like Amphetamine for a graphical toggle.

Step-by-Step

  1. Plug in your Mac. Most methods require the Mac to be connected to power. If you're using a MacBook, connect the MagSafe or USB-C charger.
  2. Connect an external display and input devices. Attach the display via HDMI, DisplayPort, or Thunderbolt. Pair or plug in a keyboard and mouse/trackpad, because the built-in keyboard and trackpad won't work when the lid is closed.
  3. Open Terminal. Go to Applications > Utilities > Terminal, or press Cmd+Space and type "Terminal" then hit Return.
  4. Enter the command to disable sleep on lid close. Type the following command and press Return:
    sudo pmset -a disablesleep 1
    You'll be prompted for your admin password. Type it (it won't show characters as you type) and press Return.
  5. Verify the setting. Type pmset -g and press Return. Look for disablesleep 1 in the output. If you see it, the setting is active.
  6. Close the lid. Your Mac should now stay awake, and the external display will show your desktop.
  7. To revert to normal behavior later: Run sudo pmset -a disablesleep 0 in Terminal and press Return.

Common Mistakes

  • Not plugging in the power adapter. If your Mac is on battery, closing the lid will almost always force sleep, regardless of the setting.
  • Forgetting an external display. Without an external display, the Mac will sleep when you close the lid because it has no way to show the desktop.
  • Typing the command with a lowercase 'L' instead of a one. The command uses the digit 1 (one) to enable and 0 (zero) to disable. A lowercase L will cause an error.
  • Using sudo pmset -a sleep 0 instead. That command disables normal sleep but does NOT prevent lid-close sleep. You need disablesleep specifically.
  • Not checking if the setting took effect. Always verify with pmset -g to avoid surprises.

Tips

  • Use Amphetamine for a GUI toggle. Amphetamine is a free app that puts a small icon in your menu bar. Click it to prevent sleep, and it can auto-resume when you open the lid.
  • Create a quick shortcut. You can make a simple AppleScript or use Automator to run the terminal command with a click, but the Terminal method is already fast.
  • Keep your Mac cool. With the lid closed, airflow is reduced. Ensure the Mac is on a hard surface and not in a bag or under a blanket.
  • Use the built-in "Prevent automatic sleeping" in System Settings. Go to System Settings > Battery > Options and check "Prevent automatic sleeping on power adapter when the display is off." This helps but does not replace disablesleep.

Troubleshooting

  • Mac still sleeps when closing lid: First, verify the setting with pmset -g. If it shows disablesleep 1, try restarting your Mac. Then check that your external display is properly connected and powered on.
  • External display shows nothing after closing lid: Press a key or move the mouse on the external keyboard/mouse to wake the display. If that fails, unplug and replug the display cable, or restart the Mac with the lid open, then close it again.
  • Mac wakes from sleep while lid is closed: This is normal if you have "Wake for network access" enabled in System Settings > Battery > Options. You can disable it if you don't need it.
  • Command not found or permission denied: Make sure you are typing sudo at the beginning and that you have admin rights. If you get "command not found," you may have a typo; try copying the command exactly.
  • After a macOS update, the setting reverts: Some updates reset power management settings. Re-run the command after major updates.

Frequently Asked Questions

Is it safe to keep my Mac running with the lid closed all the time?

Yes, as long as it's on a flat, ventilated surface and plugged in. The Mac is designed to run with an external display, though prolonged use in a hot environment may reduce performance.

Will this work on a MacBook Air or MacBook Pro?

Yes, the command works on any Mac laptop. It also works on iMacs and Mac minis, but they don't have a lid.

Does this drain the battery?

If you're plugged in, it doesn't drain the battery. If you unplug it, the Mac will sleep almost immediately when you close the lid, because the setting is overridden by the battery state.

Can I use the built-in keyboard and trackpad after closing the lid?

No. When the lid is closed, the internal keyboard and trackpad are disabled. You must use an external keyboard and mouse.

Will this affect my Mac's sleep schedule?

No, it only affects what happens when you close the lid. Normal sleep settings (like display off, system sleep) still apply when the lid is open.

How do I know if the setting is active?

Run pmset -g in Terminal and look for disablesleep 1. If it says 0, the setting is off.