Keeping MacBook on When Lid Closed

I have an M1 MacBook Pro which is not connected to any external monitor. I would like to be able to keep it powered on when the lid is closed so that it will receive Apple Mail and run mail rules.

Is this possible?

If that is not possible, is there a way I can create a Shortcut or other automation on my main Mac to wake the laptop while the lid is closed?

macOS setting have changed (or at least the interface) has changed with versions >= 13 (Ventura). But in the Battery setting (behind “options” button) your can turn on “Enable Power Nap” as “always” or “only on power adaptor”. I see it, but have not yet experimented with the new setting.

I do indeed remember times past where there were settings for what happens when lid closes, but I can’t spot them anymore. Maybe some command line options, but unknown to me.

There is a built in command line feature called caffeinate. A third party app such as Amphetamine offers a GUI to it. Some info is here.

1 Like

well remembered. Here is the man file in macOS 13.0.1. Meantime, I think I’d try out the setting in Battery first as that seems to meet @rkaplan’s needs as described.

caffeinate – prevent the system from sleeping on behalf of a utility

caffeinate [-disu] [-t timeout] [-w pid] [utility arguments…]

caffeinate creates assertions to alter system sleep behavior. If no
assertion flags are specified, caffeinate creates an assertion to prevent
idle sleep. If a utility is specified, caffeinate creates the assertions
on the utility’s behalf, and those assertions will persist for the
duration of the utility’s execution. Otherwise, caffeinate creates the
assertions directly, and those assertions will persist until caffeinate

 Available options:

 -d      Create an assertion to prevent the display from sleeping.

 -i      Create an assertion to prevent the system from idle sleeping.

 -m      Create an assertion to prevent the disk from idle sleeping.

 -s      Create an assertion to prevent the system from sleeping. This
         assertion is valid only when system is running on AC power.

 -u      Create an assertion to declare that user is active. If the
         display is off, this option turns the display on and prevents the
         display from going into idle sleep. If a timeout is not specified
         with '-t' option, then this assertion is taken with a default of
         5 second timeout.

 -t      Specifies the timeout value in seconds for which this assertion
         has to be valid. The assertion is dropped after the specified
         timeout. Timeout value is not used when an utility is invoked
         with this command.

 -w      Waits for the process with the specified pid to exit. Once the
         the process exits, the assertion is also released.  This option
         is ignored when used with utility option.

caffeinate -i make
caffeinate forks a process, execs “make” in it, and holds an assertion
that prevents idle sleep as long as that process is running.



Darwin November 9, 2012 Darwin


1 Like

Thank you both - @rms and @JoePreiser

Either Caffeinate or Amphetamine will accomplish what I need

I’ve used Amphetamine for a long time. I use it to stop my iMac going to sleep when I expect to want to log into it remotely, or connect to shares. Could use caffeinate, but I don’t for whatever reason. Amphetamine is clearly more complicated than the option in Battery to enable the PowerNap which seems to enable Mail to run while sleeping which is what you wanted. But you’ll maybe find success with keeping the MacBook on all the time waiting for Mail to do it’s thing. Maybe the app “Sleep Aid” is what might work for you if looking for an app. Enjoy the journey!

1 Like

PowerNap works to import the mail. But the Mail Rule I am trying to run with the lid closed imports mail into Devonthink; that part does not seem to work consistently in PowerNap. So I will play with the other two options tonight to set that up. Thanks.

I would not expect DEVONthink to turn on during PowerNap. To make it work as you expect you have to keep the Mac “on” all the time with lid closed. But if you make your rule in Mail to send stuff to DEVONthink such that it will handle incoming next time you open it yourself the all will be ok. That is how the DEVONthink Global Inbox folder works and you can also design your Smart Rules accordingly. You do not have to depend on the Macbook being “on” all the time.

I really need to handle the import to Devonthink at the time the mail rule is run because the rule is fairly complex in that it allows for creation of a subgroup with both the email message and attachments inside the subgroup. It’s something I use regularly in my workflow. Also I do want it to run 24/7 because several people access the DT3 database so I need to keep it up to date.

Anyway Amphetamine solved the problem (thank you both!). I set it for the MacBook to never sleep even though the display can turn off when the lid is closed. It works well as hoped.

Now that we have fleshed out your real/complete needs, using Amphetamine is a great and probably best way to keep MacBook running 24/7 even with lid closed so that DEVONthink (and not just Mail) and if you want, any other programmed/scheduled activity, to run.