Disable second monitor
The problem
I have a 2008 iMac running OS X 10.7 with its mini-DVI output port connected to an second monitor via a DVI-D adapter.
It's nice having a second monitor, but it's sometimes superfluous and I would like to turn it off to conserve power.
Ideally, I would like the iMac to detect when I turn off the second monitor and then stop extending the display onto it. But that's not what happens; I need to unplug the DVI cable before the iMac recognizes it as removed.
Explored solutions
Mirroring the display: The second monitor is in portrait orientation, so mirroring turns the display into rather comically cropped square.
Moving the display arrangement to eliminate common borders: The display is still there, so applications sometimes still open up windows on it.
A hardware solution like a KVM switch or the product described here: I'd rather not.
This question is more in line with what I'm looking for, but they ultimately went in a different direction. Is there a viable solution using XRandR, though?
Finally, if there are no OS X native solutions for disabling a monitor, I suppose I must ask: is there an app for that?
One possible solution is SwitchResX, however, it costs money, and personally I would prefer an AppleScript or shell command for that purpose.