How to prevent screen lock when MacBook AC adapter is unplugged? I use my MacBook connected to an external monitor via HDMI with the lid closed, and plugged in to AC power (in closed clamshell mode). If I disconnect the power cord (usually happens accidentally), the external monitor will lose signal, USB devices become disconnected and I need to enter my password and unlock the screen. Is there any way to prevent my Mac from stopping HDMI input when the power is unplugged in closed clamshell mode?

I'm aware of NoSleep and InsomniaX, they work fine for preventing sleep when the lid is closed but they don't prevent screen lock when AC becomes unplugged (with closed clamshell mode).
Just in case you weren't aware of these options, or haven't already tried this, you could change the Battery settings under Energy Saver. 

Your question doesn't specify what version of macOS you're using, but here are some generic steps:


Go to System Preferences > Energy Saver
Select the Battery tab
Set Computer Sleep to Never
Set Display Sleep to Never
Set Graphics to Higher Performance
Make sure Slightly dim the display when using this power source is unchecked
Make sure Automatically reduce brightness before display goes to sleep is unchecked
Exit System Preferences


Let us know how you go.