How to Quit Applications on Mac Using Terminal

If you want to quit an application that running as a UI on your Mac via the Terminal you can make use of osascript. This command will terminate the applications gracefully.

Example 1:

Say you have a Google Chrome application running and you want to quit it via terminal.

osascript -e 'quit application "Chrome"'
Gracefully quit Google Chrome App using Terminal

Example 2:

You want to gracefully quit Android Studio app that's running gracefullyl.

osascript -e 'quit application "Chrome"'

How to Quit Application by Force via Terminal

If an application is not responding, then you can make use of the kill command.

For this first you need to run the ps command to find the process id - PID

ps -ef | grep 'Android Studio'        
  501  6958     1   0 12:36AM ??         0:14.38 /Applications/Android
  501  6960  6958   0 12:36AM ??         0:00.01 /Applications/Android
  501  6972  6682   0 12:37AM ttys000    0:00.00 grep Android Studio
kill -9 6958 

Note: kill -9 will force kill the application.


Have Questions? Post them here!