Command For Program Shut Down On A Mac

So, without further ado, here’s how to automatically shutdown, sleep, or restart your Mac at certain times. Automatically Shutting down, Sleeping, or Restarting a Mac As I said above, you are going to use a built-in app on your Mac to do the job, and the app is called Energy Saver.

Active3 months ago

I'm getting more interested in using Terminal as an alternative way to address solutions on my Mac. I have seen this question entitled 'Is there a better way to shutdown/restart OSX?'.

I would therefore like to know:

How to shut down, restart and sleep my Mac using the Terminal command exclusively ?

Community
SimonSimonProgram
3,73020 gold badges51 silver badges79 bronze badges

4 Answers

The command you are after is shutdown.This informs all users that the machine is going to be shutdown and tells all apps to close files etc.

The command takes a parameter -h, -r or -s to shut down, restart or sleep the Mac.

The command has to be run as root so you need to use sudo.

e.g. to reboot the machine immediately

e.g. to shutdown the machine in 60 minutes

From comments there are two things to be addressed

How shutdown works is by sending a sigterm to all processes which should then deal with that e.g. save open files etc. If they don't exit then they will get sent a SIGKILL which forces them to die with no chance to respond. The signals are not sent via the normal key message queue so Apps have to deal with this separately to the code that gets called from quit on the menu. A good app should call common code from both.

This other answer shows how to shutdown as if you hit the menu options. But note that apps can cancel this shutdown

MarkMark
20.9k12 gold badges60 silver badges98 bronze badges

Shut down without showing a confirmation dialog:

Shut down after showing a confirmation dialog:

Restart without showing a confirmation dialog:

Restart after showing a confirmation dialog:

Log out without showing a confirmation dialog:

Log out after showing a confirmation dialog:

Go to sleep (pmset):

Go to sleep (AppleScript):

Put displays to sleep (10.9 and later):

The four letter codes for the Apple events are listed in AERegistry.h.

All System Events commands above send Apple events to the loginwindow process. loginwindow is sent the same Apple events as above when you log out, restart, shut down, or put the the Mac to sleep normally. See Technical Q&A QA1134: Programmatically causing restart, shutdown and/or logout.

According to man shutdown, shutdown -h now and shutdown -r now send processes a TERM signal followed by a KILL signal.

According to the Daemons and Services Programming Guide, when you tell loginwindow to log out, processes that support sudden termination are sent a KILL signal, and processes that don't support sudden termination are terminated in different ways: Cocoa applications receive the applicationShouldTerminate: delegate method, foreground applications receive the kAEQuitApplication Apple event, background applications receive the kAEQuitApplication Apple event followed by a KILL signal, and daemons receive a TERM signal followed by a KILL signal after a few seconds.

LriLri
81.9k12 gold badges175 silver badges241 bronze badges

Shutdown immediately:

If you do feel like putting a delay on the shutdown, you can use the following command syntax instead:

(-h parameter set time to shut down, where (+)30 minutes to stop the system)

CamelTMCamelTM
Command For Program Shut Down On A Mac

also useful, to logout from the terminal command line prompt, type 'exit':

holbeinholbein

How To Force A Program Shut Down On A Mac

You must log in to answer this question.

Command For Program Shutting Down On A Mac

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