Apple - How can I sleep the display from Terminal?
In OS X 10.9, you can simply do pmset displaysleepnow
. This will immediately turn off your display without changing any of your settings or putting the entire host to sleep.
Escalated privileges don't seem to be required (at least with recent versions of OS X), but if you get a message about inadequate privileges, you could do sudo pmset displaysleepnow
.
Based on feedback from commenters, this is not available in OS X 10.8 or earlier.
While I haven't been able to find a command that will sleep the display natively, there is an app you download that will do it. There are two options from here.
Install the app to the Applications folder and from Terminal or SSH run
open /Applications/Sleep\ Display.app
Right click on the app from the Downloads folder and click "Show Package Contents". Navigate to
Contents/MacOS
and copy the sleepdisplay file.Navigate to
/usr/bin
(you can use the ⇧+⌘+G shortcut and type the directory in) and paste the binary file. You will now be able to type the commandsleepdisplay
into Terminal or through SSH and the display will immediately go to sleep.
Hope this helps!
Here's a simple shell script that will do it.
#!/usr/bin/env bash
open /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app
This will run/start whatever settings you have enabled for Screen Saver on that computer.