applescript – Upon my shoulder http://www.uponmyshoulder.com/blog // TODO: insert witty tagline Tue, 20 Jun 2017 20:25:30 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.8 Put OS X to sleep via command-line http://www.uponmyshoulder.com/blog/2010/put-os-x-to-sleep-via-command-line/ http://www.uponmyshoulder.com/blog/2010/put-os-x-to-sleep-via-command-line/#comments Thu, 25 Mar 2010 15:25:13 +0000 http://localhost:8888/wordpress/?p=81 When connecting to an OS X box via SSH, you may want to put it to sleep after you’re done.

This is no system call to put the computer to sleep that I know of. However, Applescript can do it, and it is trivial to call the OSAScript interpreter in bash.

The following script puts the computer to sleep:

#!/bin/bash

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

Edit: found a better way!

I don’t know if this is specific to Snow Leopard, but the following command will work as well without having to use Applescript or administrator rights:

pmset sleepnow
]]>
http://www.uponmyshoulder.com/blog/2010/put-os-x-to-sleep-via-command-line/feed/ 13