Prevent macOS from going to sleep when lid closed with KVM

I recently got a KVM switch which allows me to quickly switch between two computers, one being a M2 MacBook Pro. The problem is that once the monitor switches to the other computer, the Mac goes to sleep. Audio stops playing, and when switching back it takes a tap of the keyboard and mouse movement to wake it back up. It’s really annoying.

This solution doesn’t require installing any 3rd party software such as Amphetamine or Sleep Blocker. It doesn’t require you to change any macOS settings, nor does it require you to spend money on any hubs, docking stations, dongles, or any other hardware.

Here’s the free solution. It works for me, and I hope it works for you.

Open up the Terminal Mac app and enter this:

sudo pmset -a disablesleep 1

To revert, change the 1 to 0 and run it again. It will prompt you for your password, just enter it and it immediately solves the problem. No restart necessary.

The downside, of course, is that when your Mac isn’t docked at your desk plugged into an external monitor, it won’t properly go to sleep when you expect it to.

Additionally, you’ll notice that when you go to your Apple menu, the Sleep option will be disabled. You need to run that command again in Terminal with 0 instead of 1 to go back. My advice? Bookmark this page like I have so you can quickly refer to it in the future.

This is working for me with the latest macOS Sonoma developer beta (as of the date of this post) so hopefully it will work for you!

No Replies to "Prevent macOS from going to sleep when lid closed with KVM"


    Leave a Reply