While shutting down and restarting your computer might sound trivial, and are perhaps obvious tasks in most cases, there are a number of ways to go about doing these on your Mac, many of which you might not be aware of.
Some of the approaches for shutting down and restarting may be preferred in most situations, but others might be better suited when your Mac is unresponsive, or is otherwise in a jam where the standard options are either not available or not working properly.
The Apple menu
The standard ways to restart and shut down your Mac are in the Apple menu. These options will close each program as cleanly as possible, allowing you to save documents and settings, and quitting them only when they are ready. If a program cannot be cleanly stopped, then it will prevent the shutdown or restart from proceeding.
One option in these routines allows you to interface with Apple’s Resume feature, where in the confirmation dialogue that appears you can check the option to have OS X re-open all of your current programs, if desired. As a word of note, if you hold the Shift key immediately after entering your password at the login window, you can prevent any prior program from opening, and just open your account to the Desktop.
Finally, when you select these options the system will prompt you with a warning to be sure you want to invoke them; however, if you hold the Option key then you will see the little ellipsis (three dots) next to each disappear, and selecting them in this mode will prevent this prompt from displaying. This may be a quicker option for you if you are sure you want to perform these actions.
Since they are the gentlest approaches, in most cases you will use these methods for restarting and shutting down your Mac.
Another approach you can use for restarting your Mac is to use the Terminal, where there are several commands available performing these actions:
sudo shutdown -r now
In addition to “shutdown,” you can use the “reboot” and “halt” commands in similar manners:
sudo reboot sudo halt
These commands will be a little more crude when compared to GUI options, as they will force programs to quit instead of stopping the shutdown process if a program is busy. As a result, they are beneficial to use if the Apple Menu options to not seem to work.
A final Terminal-based option allows you to invoke the standard Restart and Shut Down in the Apple menu, by simply running the AppleScript commands that invoke these reboot actions:
osascript -e 'tell application "System Events" to restart' osascript -e 'tell application "System Events" to shut down'
These last two are perhaps best to use in scripts for scheduled tasks, but in order to work will require your user account be logged in.
Terminal-based approaches can be used for restarting remote systems such as servers; however, if you have FileVault enabled on your remote Mac, then you will run into an issue where the system will restart but then need to be unlocked before OS X can load. Unfortunately without OS X loaded there will be no way to interact with your system and control it.
This problem will occur even if you use Screen Sharing; therefore you need to use the following special command to reboot any FileVault-enabled Mac and have it resume without first needing to be unlocked:
sudo fdesetup authrestart
This command will store your password temporarily for one reboot session, and then restart your system so the disk will be unlocked.
While you can create scripts using the above Terminal commands to restart and shut down your Mac, you also have these options in the Energy Saver system preferences, where you can set your Mac to shut down at a specific time each day, or on specific days of the week. To do this, click the Schedule button at the bottom-right of the Energy Saver system preferences, and then check the options to enable startup or shutdown, followed by setting their schedules accordingly.
This option is perhaps best for managing security and running scheduled maintenance tasks for your various purposes. While it can be useful in some circumstances, in most situations for a personal computer it can be cumbersome and interrupt your workflow if you forget about it.
Scheduling restarts and shutdowns in this manner can also be done in the Terminal using the “pmset” command, which adjusts the system’s power manager in the same ways as the Energy Saver system preferences. This can be done in two ways: a one-time event, and a repeated event. For example, the following will schedule a one-time event to shut down at midnight on January 1, 2015.
sudo pmset schedule shutdown "01/01/15 00:00:00"
To have your Mac always shut down on a specific day, you will need to use the “repeat” option for the “pmset” command, such as the following to have it shut down on midnight every day (note that the times in these commands are in 24-hour format).
sudo pmset repeat shutdown MTWRFSU 00:00:00
You can look up more about the pmset command and its options in the pmset manual page.
Your Mac’s power button
The last approach to restarting and shutting down is to use the power button on your Mac, which has several modes you can use. The first is to hold the button for only a few seconds, where you will see the power panel appear with options for restarting, shutting down, or sleeping your Mac (note you can also press Control-Eject on Macs that have an Eject key). At this panel, you can press the “R” key to restart, or use the tab key to highlight your desired choice followed by invoking it with the Space bar.
This approach will invoke the standard Shutdown and Restart procedures as can be accessed from the Apple menu, and will similarly be relatively gentle on programs. However, this also means that if your Mac is unresponsive and you cannot open the Terminal, then this likewise may not allow you to shut down your system. Therefore, as a last resort, you can perform a hard shutoff of any Mac by holding the Power key down until the system powers off.