You don't need paid apps to do this as it's very simple using Bash (the default shell in Terminal).
You can have the computer shutdown by issuing the command in Terminal
$ sudo shutdown -h now
If you try it, it will shutdown your Mac immediately.
What each part does
sudo
= run as the root user
shutdown
= the command to shutdown the system
-h
= halts the system
now
= immediately
So, if you wanted to shut the computer down 5 minutes from now, your command would be:
$ sudo shutdown -h +5
You can even schedule it for a reboot (-r
instead of -h
) at a particular time (11:00pm every night)
$ sudo shutdown -r -h 23:00
While that command all by itself, would do what you want, it's limited because of sudo
; you'll need to enter your password when it's run. This means you'll have to be on-prem at each machine each time you want to issue the command (every day), so we need something that will run the command as root
so it will be automatic.
Writing a Bash Script
The script for this is quite simple; it's a single line that calls the shutdown command:
#!/bin/bash
/sbin/shutdown -h now
Call it auto_shutdown.sh
and save it to a convenient location. Make it executable by issuing the command:
$ sudo chmod +x auto_shutdown.sh
This will set the execute bit and allow the system to process it as a program. Now you have your script, you just need something to execute that script at a predetermined time.
Using Launchd
to schedule your job
launchd
is the service management framework that starts/stops/restarts processes, services, daemons, etc. To set up a job to kick off with launchd
you need two items:
- type of job to be run; run as the user for one user, as the user for all users, or a job run by the system as
root
. We want the last one.
plist (XML file) that describes the job. The key elements that you need to focus on right now are the ProgramArguments
that calls the script and the CalendarInterval
which specifies when the jobs should be run. For this example, call your plist user.com.autoShutdown.plist
(no other reason for that naming convention other than it follows Apple's conventions.)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.autoShutdown</string>
<key>ProgramArguments</key>
<array>
<string>/Path_to_Script/auto_shutdown.sh</string>
</array>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>21</integer>
<key>Minute</key>
<integer>30</integer>
</dict>
</dict>
This plist is set to run the auto_shutdown.sh
script every day at 11:30pm.
Since we want to run this as root, copy the plist to the /Library/LaunchDaemons
directory.
$ sudo cp com.user.autoShutdown.plist /Library/LaunchDaemons
Finally, load the job into launchd
:
$ sudo launchctl load com.user.autoShutdown.plist
That's it. Every day at 11:30, the system will automatically shutdown.
Replicate across all your machines
Copy both the script and plist to each machine and load the job into launchd
. You have just set the shutdown time for all machines and it didn't require 3rd party ($$$) utilities.
You can find info on all the commands listed here by looking up their man page. Type man <command>
for the command you're interested in.
poweroff
? You would have to run it as a system dameon (as root) and schedule it with launchd.