I'd like to be able to turn my screen off from command line.

I know there's the keyboard shortcut ctrl++ but I want to do it from a shell script or remotely.

Is there a way?

15 Answers 15


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.

  • It's not in 10.8; I just checked. – adiabatic Nov 16 '13 at 0:30
  • 1
    For some reason I don’t need escalated privileges on my machine (with a clean Mavericks install). – Lenar Hoyt Mar 8 '14 at 3:51
  • 6
    FYI: To use this with any keyboard shortcut you want to put the display to sleep you can use Automator -> New -> Service. Then search "run shell script" in the "actions" tab. Drag it to the right side. Instead of "cat" put "pmset displaysleepnow" as proposed above. Select "no input" from the "service receives selected". Save (cmd+s) it as whatever name ie. "SleepDisplay". Then go to System Preferences -> Keyboard -> Shortcuts -> Services and on the bottom of the list you find your command. Assign any shortcut you like. – steros Aug 15 '14 at 19:05
  • 4
    As a sidenote: use caffeinate -u to wake the display again. – Asmus Dec 12 '14 at 13:03

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.

  1. Install the app to the Applications folder and from Terminal or SSH run open /Applications/Sleep\ Display.app

  2. 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 command sleepdisplay into Terminal or through SSH and the display will immediately go to sleep.

Hope this helps!

  • 1
    +1 I was just about to post the same! I guess this is the best way. I'll up vote this as soon as I'm allowed again. I've reached my limit for today. :) – gentmatt Jan 12 '12 at 14:57
  • 6
    You'd rather put it in /usr/local/bin, so as not to risk anything messed up in the system, have it survive potential system upgrades and whatnot. That's what /usr/local is for after all. – Lloeki Jan 13 '12 at 9:57
  • Yeah, @Lloeki is right. My bad! – Matt Love Jan 13 '12 at 13:33
  • 2
    No we're not getting confused. This is dictated by the FHS. Every single opensource package worth its salt has a --prefix defaulting to /usr/local for this reason. On Mac OS X (which respects the FHS, mostly, except for /users which got inherited from some other unixes) /usr/local/bin, although nonexistent on the filesystem by default, is in the default PATH. Just create it. – Lloeki Jan 14 '12 at 17:06
  • 1
    Matt should get credit for the correct answer here, but just to note that you can run 'open -a SleepDisplay' via ssh and it will immediately turn off the screen (or, yes, you can do cp /Applications/SleepDisplay.app/Contents/MacOS/sleepdisplay /usr/local/bin/ if you want it in your path. Then you can just type sleepdisplay and it will, even over ssh, dim the monitor. I just tested this on my iMac, ssh'd from my MacBook Air. Both running 10.7. – TJ Luoma Jan 17 '12 at 15:18

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.

  • I like this one. I copy/pasted this code into a file /usr/local/bin/ss, chmod +x on it, and can now type 'ss' in a commandline to make the screen saver activate. The screen saver in turn is configured to ask for a password one minute after activating the screen saver (which could be lowered further, I believe, if needed) – fwielstra Jan 27 '12 at 10:15

The following script will do the job (in Leopard and later), but it must be run with sudo:

The premise is that pmset can set a time until display sleep, but the problem is that a value of 0 turns the feature off, rather than setting the delay to zero, and a value of 1 is a full one minute delay. The magic here is that a value of 2^31 seems to be stored as negative zero, which magically functions as "turn the display off immediately". In Tiger and earlier, a different magic number was needed, because a different bit-sized variable was used internally to store the delay, in minutes, until the display turns off.

This mimics the behavior of control-shift-eject, and can be used on MacBook Airs without an eject key.

original_setting=`/usr/bin/pmset -g | /usr/bin/grep displaysleep | /usr/bin/awk '{print $2}'`
/usr/bin/pmset -a displaysleep $magic_number; sleep 1; /usr/bin/pmset -a displaysleep $original_setting
  • That didn't seem work if the original setting was 0 (never). You could add something like [[ $original_setting == 0 ]] && original_setting=180. – Lri Jan 17 '12 at 1:59
  • A minor note: using 'grep' to match a line to feed to 'awk' is extraneous; this is what 'awk' is for. Get rid of the grep and use awk /displaysleep/ {print $2}' – kundor Feb 13 '14 at 17:53
  • @kundor Your suggestion doesn't work; the grep is needed. – Teemu Leisti Feb 8 '17 at 11:36
  • @TeemuLeisti it seems to be missing a single quote before the first slash; is that what you mean? I assure you, using grep to match a pattern and awk to act on it is equivalent to using awk to both match the pattern and act on it. – kundor Feb 8 '17 at 12:22
  • @kundor Yes, adding the quote before the first / made your example work. I'd assumed a quote was missing from in front of the {, instead. – Teemu Leisti Feb 9 '17 at 10:27

Run the following command to execute a short AppleScript that puts the display to sleep:

osascript -e 'tell application "System Events" to sleep'

The command name suggests that it might put the entire system to sleep under some circumstances, but I could not make that happen in limited testing: I tested it with a shell script I started shortly before executing this command, and that was running for a few minutes until I "awoke" the system. It had continued to print output during the entire time.

  • 1
    Running shell scripts will delay system sleep, though the details aren't all there in my brain at the moment. – Jason Salaz Jan 6 '12 at 0:50
  • 1
    Yes something like that but just to turn the screen black (as with ctrl+shift+eject), not put the computer to sleep. It does stop the music for example. – gregseth Jan 6 '12 at 6:33
  • 1
    This is the answer. It works instantly and incudes a true sleep state. – Miles Leacy Jan 13 '12 at 19:32
  • 2
    @MilesLeacy Thanks, but that's not what the user asked for. Apparently it sleeps the machines completely (it didn't when I tested it). Keeping the answer up for others' reference only. – Daniel Beck Jan 13 '12 at 19:56
  • On 10.9 (at least) this does sleep the entire system. – Ryan Jun 28 '14 at 22:11

on macOS Sierra

  • sleep display : pmset displaysleepnow
  • wake display : caffeinate -u -t 1
  • test state : pmset -g powerstate IODisplayWrangler | tail -1 | cut -c29 results <4 are a sleeping display

a small node HTTP server to set screen status of your Mac remotely: https://github.com/ycardon/switch-api


Really hope this answer isn't too off the beaten track. My favourite way to sleep, restart, shut down - and most importantly lock - a Mac is using Alfred (the app launcher).

It doesn't require any scripts, knowledge of scripts or use of terminal, which is brilliant.

However, if you specifically WANT to use terminal, this probably isn't the solution for you.

  • While this is really cool, there are two limitations: 1) Alfred has no option for displaysleep 2) These special commands in Alfred only exist when your system language is English. – gentmatt Jan 16 '12 at 16:05
  • 1
    @gentmatt While #1 is correct, #2 is wrong. My system language is Finnish and the special commands happily exist & execute. If you want to localize the triggering commands you can do it under Alfred's PreferencesFeaturesSystem CommandsSystem. – Jari Keinänen Jan 16 '12 at 17:54

Wake: caffeinate -u -t 2

Sleep: pmset displaysleepnow

  • I have no idea why this was downvoted; using caffeinate to wake the display works. (You can use a lower timeout in my experience, i.e., caffeinate -u -t 1.) – Nicholas Riley Mar 18 '17 at 16:47

You could use the pmset command to change the value for displaysleep, something like

pmset -a displaysleep 1

(requires root)

  • 2
    This is a good option as well, the only downside is that it will cause a one minute (hence the 1 at the end of the command) for the display sleep. Just thought Daniel Beck should know. – Matt Love Jan 12 '12 at 16:26
  • 4
    Isn't this permanent? If it's just supposed to be used once when needed you need to use force: sudo pmset force -a display sleep 1 – gentmatt Jan 12 '12 at 17:09

Take a look at the open source github project maclock

By default, it just launches the screensaver, but you can put the display to sleep with:

maclock --display

Under the covers, it is a bash script that is essentially just calling:

pmset displaysleepnow

Well, this is an old one, but it seems there aren't really good answers for this question anywhere.

I've gotten an AppleScript to work, though it requires a third-party, unmaintained, and un-registrable app—Extra Suites. It can be downloaded on the developer's old website.

# Gets the current state of the upper left hot corner, then sets it to sleep display.
tell application "System Events"
  tell expose preferences
    set givenActivty to get the activity of the top left screen
    set the properties of the top left screen corner to {activity:sleep display}
  end tell
end tell

# Uses Mouse to Activate upper left hot corner. [Moving directly to {0, 0} does not work
tell application "Extra Suites" 
  ES move mouse {1, 1}
  ES move mouse {0, 0}
end tell

# Restores state of upper left hot corner.
tell application "System Events"
  tell expose preferences
    delay 1
    set the activity of the top left screen corner to givenActivty
  end tell
end tell

# Gets rid of Extra Suites nag window.
tell application "Extra Suites"
end tell

I've also incorporated it into an Alfred Workflow.


I did it with sudo shutdown -s now.

Note that you will need administrator privilege to do this though.


Using Alfred (free at the AppStore) is a great way to put the display to sleep by just writing: "sleep". Doesn't get simpler than that.

Of course Alfred does much more than that, you can also restart, logout, empty trash, lock, shutdown and many more things.

  • 1
    This does not address his need to do this remotely or via ssh. – TJ Luoma Jan 17 '12 at 14:36

No need extra app, just use tell application "Finder" to sleep

  • 1
    Doesn't this sleep the whole computer? – nohillside Jun 8 '14 at 19:39

The app Launchbar works equally well as Alfred. In my case, CMD spacebar then S [Sleep] - simple and fast

  • This does not answer the question. gregseth is not looking for a way to put the computer to sleep with a third-party utility, but a way to put the display to sleep from the command line. – Timothy Mueller-Harder Nov 25 '16 at 21:23

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.