Shutting Down Your Mac Safely

A few people have recently asked how Power Manager shuts down their Mac. Let's look at the two main shut down methods available and then how Power Manager strikes a balance between these two approaches.

Many of the problems with automatically shutting down your computer come from poorly behaved applications or from applications stalling while they wait for some form of interaction.

There are two basic approaches to automatically shutting down your Mac. The first is to issue a shut down AppleEvent. The second method is to use the command line tool shutdown.

Of these two methods, Apple recommends the first. In Q&A1134, Apple Developer Technical Support (DTS) recommend asking the System process to shut down through the kAEShutDown AppleEvent. This method mirrors what happens when you select Shut Down from the Finder's Apple menu.

Shut Down with kAEShutDown

Sending an AppleEvent to the System process requesting a shut down should completely power down your Mac. If all is well, your Mac will shut down in an orderly manner.

Problems arise with applications that need some interaction when they quit. Unsaved changes and running tasks that need to be stopped often end in dialog boxes asking where to save documents and "are you sure" alerts. These alerts will typically stop the shut down; in most cases leaving your Mac sitting with some applications quit and others still running.

With Mac OS X 10.7, aka Lion, Apple is moving towards an operating system design that can deal with applications seamlessly quitting and relaunching without user interaction. The design is not yet perfect and does not deal with every contingency but it is a step forward.

It is at this stage that problematic applications prompt people to look at the second shut down method. The second method is shutting down using the command line tool shutdown.

shutdown -h now

shutdown is a blunt tool that will in most cases shut down your Mac. It works at a layer below the Mac's user interface and is roughly the equivalent of force quitting everything.

With shutdown, Mac applications that would have quit nicely are not given the chance. In most cases using shutdown should be fine but care needs to be taken about denying applications of the opportunity to quit nicely.

Power Manager

Power Manager has evolved to do its very best to shut down your Mac in a Mac friendly way. Power Manager will force quit applications that threaten to block the automated shut down, but the force quit is only used after the application has been issued a friendly quit request.

Let's walk through what happens when you ask Power Manager to shut down your Mac.

Power Manager is multiple user savvy and first deals with the logged in users. The following steps happen within each logged in user's session:

  1. Running applications are sent a quit request.
  2. Running applications are given time to quit.
  3. If an application has not quit in time, the application is force quit.
  4. With all the applications quit, the user is logged out.

Once all the users are logged out, Power Manager then asks Mac OS X to shut down. You can watch this sequence play out in the transcripts of the Mac's system.log file.

Power Manager's shut down process is reliable, predictable, and Mac friendly.

System Folder Applications

There is one exception where Power Manager will not shut down your Mac. Power Manager will not force quit an application that lives within the /System folder. The contents of this folder are managed by Apple.

If an application within the System folder wants to stop your Mac shutting down, we decided it should be respected. Apple's applications should be ideal Mac citizens and quit properly when requested; if they do not, then it hints at underlying problems that need to be addressed rather than masked.

A Fine Balance

Automatically shutting down your Mac is possible. Shutting down safely and predictably just takes some effort to get right.

Power Manager's approach is to allow Mac OS X to handle as much as possible. Where needed, Power Manager applies a light touch to make sure that applications that might cause problems are dealt with first.

This article was posted in , , , and and tagged .

Published by Graham Miln on