launchd
(ref) is the preferred method for scheduling events in OS X, as opposed to using cron
.
Here is a method for putting an OS X computer to sleep at a specified time using built in OS X tools without the override alert prompt. Waking the computer up can still be handled via System Preferences → Energy Saver → Schedule.
First create the following shell script in /usr/local/bin
named sleepnow.sh
:
#!/bin/sh
pmset sleepnow
Then create a launchd
plist file for scheduling a script to be run daily. It would look like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.myschoolname.sleep</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>/usr/local/bin/sleepnow.sh</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>14</integer>
<key>Minute</key>
<integer>00</integer>
</dict>
</dict>
</plist>
You would probably want to put this in /System/Library/LaunchDaemons/
with the filename org.myschoolname.sleep.plist
. Adjust the time and name as needed.
You can load the plist using the command sudo launchctl load -w /System/Library/LaunchDaemons/org.myschoolname.sleep.plist
or reboot the computer and it should be loaded on system startup.
If you are not comfortable with using launchd
files and command line tools then search for the paid OS X app named Lingon which handles the creation of the plist file and loaded it.
Here is a good reference on pmset
, which is the command line tool for managing power setting in OS X.
Although pmset
can be used to set sleep and wake schedules, you'll still get that alert box on scheduled sleep. The pmset sleepnow
command causes the computer to go to sleep immediately without an alert.