Quit applications politely from the command line | 11 comments | Create New Account
Click here to return to the 'Quit applications politely from the command line' hint |
In the case of Activity Monitor.app it would be kill 25794 or kill -9 25794. Some more details: The kill program in Terminal simply force quits a program, as though by remote control. (It even works when you SSH into your Mac from a remote location. Follow the kill command with the process ID number (short PID) of the program you want to terminate. Oct 23, 2019 Learn how to control a remote Mac with Screen Sharing with the kickstart command-line utility in macOS Mojave 10.14 and later. Get started You can find the kickstart tool at.
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Very nice, thank you!
This script is well done and may be useful to some people. But automatically overwriting open files when you quit an application remotely isn't always 'polite.' Your cat might have been sleeping on the keyboard while you were away from your desk. If you send a kill signal to an application, at least you can be sure that no stored data has been overwritten.
That's a good point. Maybe I'll put out a new version with an option not to save.
I've just uploaded version 1.1 which includes an -n option that tells the app not to save changes.
Is it really such that OS X applications (which ARE processes, otherwise they wouldn't appear in 'ps' listings) do not catch SIGTERM/SIGINT and such to shut down cleanly? Really!?
To me this seems hard to imagine. But then I don't know better.
Yes, really. For example, the command one might expect to work as desired, To me this seems hard to imagine. But then I don't know better.
killall -QUIT TextEdit
, produces an error message saying 'The application TextEdit quit unexpectedly.' By all means feel free to play around with the various kill signals, but from what I can find, none of them perform the same way as pressing ⌘Q when using the application. Obviously every application has a process at its core, so you will see at least one process for each application, but an application is more than just a process.
I just tried it: 'killall -TERM TextEdit' works as I expect, producing no error message but just telling TextEdit to die asap. 'killall -QUIT' indeed does behave different. But SIGTERM is what's usually sent if you do not give an explicit signal.
On the other hand it's right that on SIGTERM TextEdit won't ask you for saving your half-finished document, it will discard all changes. But that's what I expect if I say 'dear program, please terminate asap'.
Now I think I understand your hint and what it's for, I got it wrong after the first read. But I am still pretty sure that most OS X programs (application or not) do handle SIGTERM and do some clean up before exiting.
Perhaps this example will help further illuminate the matter: I use an application called Journler that updates its internal database as part of its quitting procedure. On the other hand it's right that on SIGTERM TextEdit won't ask you for saving your half-finished document, it will discard all changes. But that's what I expect if I say 'dear program, please terminate asap'.
Now I think I understand your hint and what it's for, I got it wrong after the first read. But I am still pretty sure that most OS X programs (application or not) do handle SIGTERM and do some clean up before exiting.
killall Journler
kills the app without triggering that procedure. For further reading, you might be interested in this.
Mac Kill Command
This script was exactly what I was looking for. I am running an iTunes 9 Home Sharing server on an alternate account under Fast User Switching. This is serving the iTunes 'master library' for my family. The iMac it runs on is also a family computer for the kids.
Of course, I frequently need to administer the master library to keep it synced with purchases that have been loaded into individual users' libraries. With this script I'm able to ssh into the iMac FUS account, close down iTunes, then open the same iTunes library on my laptop without interrupting anyone's iMac session.
If the current iMac user is running a second copy of iTunes, this script doesn't seem to see it; it closes down the FUS iTunes session without asking me to choose between the processes. The script does generate a warning message (twice):
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
but this doesn't seem to interfere with its successful execution.
Just a note that version 1.3 is available. Of course, I frequently need to administer the master library to keep it synced with purchases that have been loaded into individual users' libraries. With this script I'm able to ssh into the iMac FUS account, close down iTunes, then open the same iTunes library on my laptop without interrupting anyone's iMac session.
If the current iMac user is running a second copy of iTunes, this script doesn't seem to see it; it closes down the FUS iTunes session without asking me to choose between the processes. The script does generate a warning message (twice):
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
but this doesn't seem to interfere with its successful execution.
Usage: quit [-a] [-p] [-s|n] application names
Arguments are the names of one or more applications.
Arguments are not case sensitive.
Arguments with spaces should be quoted.
Options:
-a Match argument string with any of the application's name, displayed name, short name, or title. E.g.: `quit 'Microsoft Word'` and `quit -a Word` will both quit Microsoft Word, because the app calls itself 'Word' in the menu bar.
-p Use partial matches (e.g. edit for TextEdit). Prompts for confirmation.
-s Attempt to save modified files when quitting. Overrides any previous -n option.
-n Do not attempt to save modified files when quitting. Overrides any previous -s option.
If neither the -s or -n options are specified, quit will try to detemine if any documents require saving, and if necessary will ask the user whether to save or not.
Mac Os X Kill App Command Line Free
This script is super useful and helped me schedule cron jobs on a kiosk running Snow Leopard. It was the only thing that would let me automate the closure of an OpenOffice Impress presentation (although I had to execute 'quit' twice while in a full-screen presentation for some reason). On another note, where should I copy custom scripts to so that they can be executed globally? Or how do I modify the included path to include a folder with custom scripts? Thanks!