3

Sometimes, when I have many applications open doing many memory and IO-intensive things, my computer inevitably starts to thrash a bit. While waiting for things to settle down, I often decide to close some applications that don't really need to be open. The trouble is that many of the applications (especially ones that have background/idle processes) tend to be intermittently unresponsive until the thrashing subsides, so it either takes a very long time for them to get focus to send +q, or when I go to close them by clicking on their icon in the dock I am only presented with the option to force quit. I know that those applications aren't permanently unresponsive, so I'd prefer to send them a gentle TERM signal and have them quit gracefully when they are able. I usually end up killing them by using pkill from the terminal, however, that's not always feasible, especially if the terminal is also hosed.

What is the easiest way to gently send the signal to kill a process if/when that process is intermittently unresponsive? (In a situation in which access to the terminal and/or starting a new application is not convenient.)

2

You should be able to use AppleScript:

tell application "name" to quit

Using 'to quit' rather than 'to force quit' will mean that it won't be forced regardless of whether the app is unresponsive—rather, it will ask the app to quit whenever it can.

With shell:

osascript -e 'tell application "name" to quit'
  • Isn't that functionally equivalent to using pkill to send a SIGTERM? I was hoping there would be some way to avoid using the shell. Is there a convenient way to run an AppleScript command on the fly without either being in the terminal or running the AppleScript editor? – ESultanik Jul 10 '14 at 17:48
  • I am going to accept this answer because, barring any future additions/changes to OS X, this is probably the best I am going to get. I wrapped that command in a larger ActionScript script that enumerates all running processes and prompts me for which one to gently quit. I've the code for that in a blog post. – ESultanik Feb 23 '15 at 20:34

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.