Search code examples
swiftxcodemacosterminalrestart

Is there a way to kill all applications and restart the Mac from the terminal?


Is there a code to run in the terminal that I can use to close all applications and restart the mac? I am currently using "osascript -e 'tell app \"System Events\" to restart" to cause a restart, but it isn't closing the applications. - I need for the code to all be in one command, so I can put it in my code without one canceling out the other.


Solution

  • shutdown will close the apps automatically for you (they may not save their working files, however):

    Shutdown:

    $ sudo shutdown -s now
    

    Restart:

    $ sudo shutdown -r now