There are cases when using the terminal to quit an application is helpful, especially when it’s on a remote computer. I often use this at the office to kick off people who are holding back an update the needs to be done, or who are just playing around and not getting work done. This same action could be done via the Finder, using Screen Sharing, but it is more stealthy to do it via the Terminal.
Three Ways To End It
Let’s say you want to quit the application Safari on your co-worker’s computer, since you can see she is just looking at lolcat images on the other end of the office. You would prefer to not make a scene, so you will just quit the application for her, so she can focus on her work again.
Method 1: The soft quit with Applescript
Did you know you can actually run applescript commands via the Terminal? By using the “osacript” command you can execute any valid applescript. This method quits the program as if it was quit from the File menu, asking to save files if needed.
osascript -e "tell application 'Safari' to quit"
This soft method is good when you want to remotely quit a program a user currently using, without being a complete dick and losing their un-saved data.
Method 2: Hard quit with Killall
This method quits the program as if you initiated a Force Quit on it, which is commonly done via the Apple menu or by option-clicking (right-clicking) the application on the dock. This command will not ask the user to save files, so any unsaved data will be lost. Best used if a soft quit doesn’t work and you need to get the application closed.
Unfortunately for these two methods you first need to know the name of the application you want to stop. If you don’t know which applications are open, don’t worry, you can find out that information too.
Method 3: Selectively killing
This two step process will let you find the program you want to kill, and kill it. First, find the currently running applications.
ps -ax | grep Applications
This will give us the list of all the standard applications that are running. For a complete list of all the processes you can use the simple command “ps -ax”. From the list, find the applications that you want to quit, and take note of the number on the left. This is the pid, the Process ID. You will use this to kill the application.
sudo kill <pid>
Replace <pid> with the pid of the process you want to kill.
Go forth and use this new knowledge for good, not for evil (even though the evil options are so much fun).