Apple - Prevent Mac to sleep when lid closed on Mojave / Catalina

You can accomplish this in terminal. No additional software needed.

Display global power settings:
pmset -g

System-wide power settings:
Currently in use:
 lidwake              1
 autopoweroff         1
 standbydelayhigh     86400
 autopoweroffdelay    28800
 proximitywake        1
 standby              1
 standbydelaylow      10800
 ttyskeepawake        1
 hibernatemode        3
 powernap             1
 gpuswitch            2
 hibernatefile        /var/vm/sleepimage
 highstandbythreshold 50
 womp                 0
 displaysleep         10
 networkoversleep     0
 sleep                1 (sleep prevented by sharingd)
 tcpkeepalive         1
 halfdim              1
 acwake               0
 disksleep            10



To stop sleep entirely:
sudo pmset -a disablesleep 1

To revert, allowing sleep again:
sudo pmset -a disablesleep 0


Option 1

If you want something that’s user-friendly and a tray icon is what you need, the updated version of Caffeine should do the trick. It’s free and open-source, and runs on Big Sur!

Option 2

Don’t like installing stuff? caffeinate still works on the latest macOS.

Just open up a terminal and type caffeinate to pause sleeping, and press CTRL+C to enable sleeping again.

If you’re compiling something or rendering using the command line, you can run caffeinate my-command to pause sleep until the command finishes. You can also use the -t seconds flag to choose the maximum number of seconds to stay awake.

You also say it’s not user-friendly, but it’s super easy to set up with Automator! Create a Quick Action that uses the shell to run caffeinate and save it, then create another Quick Action to run killall caffeinate. You can then set shortcuts to them in Settings > Keyboard > Shortcuts > Services! Now, you can activate and deactivate sleeping without even opening up a terminal, and without needing sudo.