2

I need to know if there's a proper way to close apps via ssh and if it's posible shut down the system without the sudo halt or sudo init 0 (because I think those ways are not good for the system when there are apps running)

4

I have to start by saying that there is nothing wrong with using halt or shutdown from the command line.

In fact if you issue either of those commands then any running applications will get exactly the same message from the system as if you chose "Shut Down..." in the Finder.

The advantage of using sudo shutdown is that you can shutdown the system regardless of which users are logged in.

  • If I exec halt or shutdown the running apps will appear when I log in next time :/ – naoxink Jan 23 '14 at 9:37
3

To close apps, use

osascript -e "tell application \"Mail\" to quit"

Replace Mail with the name of the application you want to quit.

To shutdown correctly, use

osascript -e "tell application \"Finder\" to shut down"
  • I guess i can have aliases of that in my .profile, right? – naoxink Jan 23 '14 at 7:56
  • @naoxink Indeed – grg Jan 23 '14 at 8:19
  • If you are going to use osascript in a shell script or the command line then you have to be incredibly careful with quote characters and spaces. The first version of this answer had them all wrong. Also, this method will only work if the user logged on to the Mac and the ssh user are the same and there are no other users logged on. – Tony Williams Jan 23 '14 at 9:35
  • I suppose it will be something like this: alias myHalt='osascript -e "tell application \'Finder\' to shut down"'. Am I right? Anyway it seems to be more issues with this method than halt option :/ – naoxink Jan 23 '14 at 9:50

You must log in to answer this question.

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