Keep MacBook Pro awake in a clamshell mode + HDMI switcher setup

Solution 1:

You can use caffeinate from the terminal.app.

Just open the terminal.app and type caffeinate

Without arguments it just stays awake until you ctr+C at the terminal. There are more arguments you can use in order to prevent different system components from sleeping.

Solution 2:

InsomniaX is a third party program designed to do just that: disabling the sleep mode on a Apple laptops.

The program can prevent the Mac entering sleep mode from closing the lid or just idling (or both, of course). It's also possible to disable the sleep mode as per timer, after which the sleep mode kicks in normally.

Solution 3:

If InsomniaX doesn't work, you could also try macosx-nosleep-extension.

Or try to restore the pre-10.7 clamshell mode behavior by running

sudo nvram boot-args=iog=0x0

and restarting. When the laptop is connected to an external display, it makes closing the lid put the laptop to sleep, and it makes the internal display stay disabled even after the lid is opened.