MacOS – Easiest way to gently kill an intermittently unresponsive application

applicationsmacos

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

Best Answer

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'