Getting Mac OS X in Standby with Shell Command

Sometimes you leave the house and you Mac has to run for a little while, but then you want it in standby.
Here is a easy way to do this with a shell command.

sleep 900 && osascript -e 'tell app "Finder" to sleep'

This sets a 900 seconds (15 minutes) waiting time before putting the Mac into the sleep mode.

3 Responses to Getting Mac OS X in Standby with Shell Command

  1. andi says:

    Did not work for me.

    2011-01-23 01:47:07.803 osascript[74765:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find:
    /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
    osascript: OpenScripting.framework – scripting addition “/Library/ScriptingAdditions/Adobe Unit Types.osax” declares no loadable handlers.
    andreas-ditlers-macbook:~ andi$

  2. David Wehr says:

    It didn’t work for me either, but this does:

    sleep 900 && /usr/bin/osascript -e ‘tell application “System Events” to sleep’

  3. Ivailo says:

    Using MacOS 10.5.2 this script falied for me. the awks you did on ioreg came back with the pipe character. Also the MaxCapacity grep matched 3 lines.Instead of being reliant on the result being on a specific column, I used sed to look for the value after the equal sign. I also changed the grep on the MaxCapacity line to egrep and match a whole word, thereby eliminating the other matches (AbsoluteMaxCapacity). Here are the first two lines changed to suit:set current_capacity to do shell script “/usr/sbin/ioreg -w0 -l | grep -E ‘CurrentCapacity’ |sed ‘s/.*= \(.*$\)/\1/'”set max_capacity to do shell script “/usr/sbin/ioreg -w0 -l | egrep -wE ‘MaxCapacity’ |sed ‘s/.*= \(.*$\)/\1/'”You will see I had to escape the sed backslashes for the applescript.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.