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)
2 Answers
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
orshutdown
the running apps will appear when I log in next time :/– naoxinkJan 23, 2014 at 9:37
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"
-
-
-
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. Jan 23, 2014 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 thanhalt
option :/– naoxinkJan 23, 2014 at 9:50