To keep your MacBook on when you close the lid, go to System Preferences Energy Saver. Then select the Power adapter tab and set the turn display off after slider Never.
Note: To keep your MacBook running when you close the lid, you have to plug it into an external monitor. In addition to this, you’ll also need an external keyboard and a mouse.
Open the Apple menu cou can access this by clicking the Apple icon in the top-left corner of your screen. Then choose System Preferences strong Next, click Energy Saver This is the button with the light bulb icon Then click the Power Adapter You will see this at the top of the window. Set the Turn display off after Never Connect your MacBook to a power source, an external keyboard, a mouse, and an external monitor. Finally, close your MacBook lid to see if it’s still on.