Putting the display to sleep (โ‡ง ^ โ / shift + control + eject) in AppleScript

Is it possible to write AppleScript to hold the display (which blocks the display if the computer is configured to lock sleep)? You can do this from the keyboard by typing โŒƒโ‡งโ ( shift + control + eject ); it leaves all programs, etc., works and just turns off the screen.

+6
source share
5 answers

Edit 2015-08-23: It is possible (from the shell) with OS X 10.9! Go see user3064009 update response :-)


There is no good way to do this; there SuperUser question about the same. However, depending on why you want this, there is one way that I know: activate the screen saver. (This is what they offer on SuperUser). You can do this in AppleScript using the launch application id "com.apple.ScreenSaver.Engine" or from the command line by running the /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine application. I don't know if this is technically documented anywhere, but now it works for several iterations of the OS. It may not do exactly what you want - your screen saver may, for example, be colorful, which is unsafe if you want a black screen, but it will be the same as if it locked the screen if you have this set up .

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

  • There is no way to write scripts.
  • You cannot tell AppleScript key code EJECT as there is no such key code.
  • You can use pmset to show that the display goes into sleep mode in one minute, but then you need to wait.
  • There is an undocumented IOKit method; there is a mailing list explaining how.
+3
source

I would like to do this for a while. I just found out how on the pages of the manual. You can use the following command to achieve instant sleep sleep. (I tested it on OS X 10.10.)

 pmset displaysleepnow 

(no root / sudo privileges!)

I'm not sure if this works for 10.9.4, but of course give it a chance!

+15
source

you can use: tell application "Finder" to sleep

Or use bettertouchtool. This is a small application where you can use your own functions in addition to applescript.

+8
source
 do shell script "pmset displaysleepnow" 
+2
source

I did not find an easy way to do this programmatically, but I found a very small free application that immediately displays a display called "SleepDisplay". (There is another application with the same name that does NOT work for me.)

So you can just

 tell application "SleepDisplay" to activate 

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

+1
source

Source: https://habr.com/ru/post/898913/


All Articles