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.)

1 Answer 1

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'
2
  • 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, 2014 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, 2015 at 20:34

You must log in to answer this question.

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