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?
|
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? |
|||||
|
|
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.
Hope this helps! |
|||||||||||||||||||
|
|
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.
|
||||
|
|
Here's a simple shell script that will do it.
This will run/start whatever settings you have enabled for Screen Saver on that computer. |
||||
|
|
Run the following command to execute a short AppleScript that puts the display 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. |
|||||||||||||||||
|
|
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. |
|||||||||
|
|
You could use the
(requires root) |
|||||||||
|
|
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. |
|||||
|