7

Shutting down the machine from the command line with e.g. shutdown -h seems as if it would not be particularly graceful, but on a scale of "Pulling the power cord out of the wall" to "Going through the standard shutdown procedure from the  Menu", how graceless is shutdown -h actually?

5

Absolutely prefer shutdown -h to pulling the power cord out of the wall. shutdown provides an opportunity for macOS to cleanly exit important underlying processes and flush file caches to storage.

Avoid shutdown

Having implemented a gentle shutdown programmatically, experience taught us that you should try to avoid shutdown -h when you have logged in users and running graphical Mac applications:

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.

Shutting Down Your Mac Safely, dssw.co.uk

Prefer kAEShutDown

If you are able, follow Apple's advice in Technical Q&A QA1134 - Programmatically causing restart, shutdown and/or logout. This advice can be summed up as: issue an kAEShutDown AppleEvent to the system.

Be aware that using only kAEShutDown has its limitations, these are discussed in How to Shut Down Your Mac Using AppleScript.

By AppleScript or Command Line

You can use an AppleScript snippet to issue the kAEShutDown using:

tell application "Finder"
    shut down
end tell

Or using the command line tool osascript:

osascript -e 'tell application "Finder" to shut down'

Counter to the macOS Approach

In terms of non-graphical processes, shutdown is reasonable. For anything graphical or at the user level, you should avoid it. Issuing shutdown is not appropriate for regular use on macOS; as an emergency measure it is fine but not as a pre-considered solution.

Users would quickly learn to avoid an application that simply issued shutdown instead of issuing the request through the AppleEvent.

  • Let's say I wanted to issue a kAEShutDown from the command line, how could that be done? (Short of writing a short snippet of code, compiling it and running it, I mean.) – Williham Totland Nov 13 '17 at 11:47
  • In terms of system services and so on, though, shutdown is somewhat, if not entirely considerate? – Williham Totland Nov 13 '17 at 19:37
  • So if a single process hangs the graphical shell, then shutdown can be issued without risk of deeper injury? – Williham Totland Nov 13 '17 at 19:42
  • 1
    These are better asked as new questions. Feel free to refer to this question in your new questions. – Graham Miln Nov 13 '17 at 19:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .