You can use a command line utility named [cscreen](http://www.pyehouse.com/cscreen/) to do that. You can wrap it in a AppleSctipt script or in Automator.