Apple - Schedule a Mac to sleep, just one time
The pmset
terminal command should do what you want. The following will put the computer to sleep at 23:45:00 on December 2, 2014. The command must be run from an administrator account though:
sudo pmset schedule sleep "12/02/14 23:45:00"
The MM/DD/YY date format cannot be changed; so, if you are used to a different format, use caution.
If you do this on a regular basis, you can write a function and save it to your ~/.profile
:
# Schedule sleep in X minutes, use like: sleep-in 60
function sleep-in() {
local minutes=$1
local datetime=`date -v+${minutes}M +"%m/%d/%y %H:%M:%S"`
sudo pmset schedule sleep "$datetime"
}
By default there is no way of doing that with the options you have in the system preferences.
But, you could do it from command line with a simple command:
sleep 10; osascript -e 'tell application "System Events" to sleep'
sleep 10
pause the execution of the following command for 10 seconds. If you want minutes or hours you must change 10 with number of seconds you want.osascript -e 'tell application "System Events" to sleep'
put the computer to sleep.
For power control of your Mac from your iPhone on a local network, I have used Off Remote which can also schedule within the next 24 hours a system action (Shutdown, Lock, Restart, Log off, Sleep) and is only $3 in the iOS store but requires installation of an additional helper app on your Mac to receive the instructions from the iPhone app.
Another answer here suggested using Power Manager software which costs $50, but I would suggest the $36 Keyboard Maestro software which is a bit less intuitive than Power Manager but has greater flexibility beyond power management. In searching for the ability to schedule my Mac to sleep, I remembered that I have this utility and was able to quickly drag and drop the macro components in KM to create a script that paused for a set period of time and then put my Mac to sleep:
…there is also an action within Keyboard Maestro to also schedule macros (to put Mac to sleep, shutdown, restart, etc.) to be triggered at designated times:
Keyboard Maestro is cheaper and much more robust for developing macros that can enhance the use of your Mac, but there is a bit more of a learning curve than the Power Manager application.