How can I forcibly shut down my Mac at an appointed time?

Ok, so further to my previous answer, I can walk you through getting cron (a built in UNIX schedule service) to run a scheduled shutdown command for you.

It will run as root and will be forced.

  • Open Terminal (/Applications/Utilities/Terminal)
  • Input sudo crontab -e

You'll need to enter your login password and then press enter.

You'll now be in a text editor (vim). Carefully input the following keystrokes.

  • Press i once (this will allow you to enter text)

Let's say you want the machine to shutdown at 2am every day, we'd now enter:

* 2 * * * /sbin/shutdown -h now

If you wanted the machine to shutdown at 2:30am every day, you'd enter:

30 2 * * * /sbin/shutdown -h now
  • When you've typed this in, press esc
  • Then press shift+z shift+z (that's uppercase "z" twice, to writes the changes and quit the editor)

You should now be dropped back to the command line where you started.

You're done!


It can be canceled though:


Halt at yymmddhhmm:

shutdown -h 1109211555

Halt in 4 minutes:

shutdown -h +4

/Library/LaunchAgents/me.lri.forceshutdown.plist:

<?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>me.lri.forceshutdown</string>
    <key>ProgramArguments</key>
    <array>
        <string>shutdown</string>
        <string>-h</string>
        <string>now</string>

    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>23</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
</dict>
</plist>

If the plist was owned by a normal user, trying to load it would result in the error launchctl: Dubious ownership on file (skipping):

sudo chown root /Library/LaunchAgents/me.lri.forceshutdown.plist

The agent can be loaded by logging out and back in, or with:

sudo launchctl load /Library/LaunchAgents/me.lri.forceshutdown.plist

sudo crontab -e

`08 16 * * * /sbin/shutdown -h now`

This would perform a normal non-forced shut down:

osascript -e 'tell app "System Events" to shut down'

This can be scheduled in System Preferences > Energy Saver > Schedule. I'm not certain that this will initiate a forced shutdown, you'd have to try it out. But that's a built in option to automate scheduled power down/up.

  • You can also forcibly shutdown the system with a terminal command (requires root):

    shutdown -h now

    You could put that command into a launchd or cron scheduled task. Check out this article for far more info on those two services.

  • You may also want to check out an application like the aptly named iWannaSleep (not sure if this forces shutdown).