Word of warning: I ran this on my MBP with external display, and switched to integrated mode. After that, my display wouldn't update anymore, and I had to VNC into my computer to change the setting back to dynamic.
A "test mode" which reverts to the old setting after X seconds might be useful.