Take the 2-minute tour ×

Is it possible to write an AppleScript to put the display to sleep (which locks the display if the computer is set to lock on sleep)? You can do this from the keyboard by entering ⌃⇧⏏ (shift+control+eject); this leaves all the programs, etc., running, and just turns off the screen.

share|improve this question
Perhaps you can remind everyone what that keystroke does? –  Ned Deily Oct 9 '11 at 6:48
Did you see the June 8th answer? I tested, works nicely. –  Arjan Aug 15 at 20:11

4 Answers 4

up vote 3 down vote accepted

There's no good way to do this; there's a SuperUser question about this same thing. Depending on why you want this, however, there's one workaround I know: activate the screen saver. (This is what they suggest over on SuperUser). You can do this in AppleScript with launch application id "com.apple.ScreenSaver.Engine", or from the command line by running the application /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine. I don't know whether or not this is technically documented anywhere, but it's worked for several iterations of the OS now. It may not do exactly what you want—your screen saver may, for instance, be colorful, which isn't helpful if you want a black screen—but it will be the same in that it does lock the screen if you have that set up.

For a nice catalog of other workarounds, check out this MacScripter thread: it documents that

  • There's no scriptable way to do this.
  • You can't tell AppleScript to key code EJECT, as there's no such key code.
  • You can use pmset to tell the display to go to sleep in one minute, but then you have to wait.
  • There's an undocumented IOKit way to do this; there's a mailing list post explaining how.
share|improve this answer
Is this still true? No way to programmatically put the display to sleep in 2013? –  Ze'ev Mar 8 '13 at 0:21
@Ze'ev: I haven't been looking, but I don't know of any, and a quick Google search didn't turn up anything. The application you linked to appears to use the undocumented IOKit method that I mention above, so it's nice that someone's packaged it up. –  Antal S-Z Mar 8 '13 at 6:16

you can use: tell application "Finder" to sleep

Or use bettertouchtool. It is a small app which you can use native functions in addition to applescript.

share|improve this answer

I haven't found an easy way to do it programmatically, but I did find a very small, free app that puts the display immediately to sleep, called "SleepDisplay." (There is another app of the same name that did NOT work for me.)

So you can just

tell application "SleepDisplay" to activate

Link: http://www.macupdate.com/app/mac/26234/sleep-display

share|improve this answer
While this may answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  bluefeet Mar 8 '13 at 1:53
Awesome job, dude. You found and answered here in just 8 minutes! :D –  Cawas Apr 16 at 13:49

I've been wanting to do this for a while now. I just found out how in the man pages. You can use the following command to achieve instant display sleep (only tested in 10.10 preview build):

pmset displaysleepnow

(no root privileges / sudo required!)

I'm not sure if this works for 10.9.4 yet but by all means give it a shot!

share|improve this answer
Works as advertised in 10.9.5 –  Claude Sep 26 at 10:54

Your Answer


