You can use a command line utility named cscreen to do that. You can wrap it in a AppleSctipt script or in Automator.
user3439894
- 59.8k
- 10
- 112
- 135