How do I close the Terminal in OSX from the command line?

Why doesn't "exit" close a Terminal.app window on Mac OS X?

$ exit
logout

[Process completed]

Is there a way to close the window without using the mouse?


A window displayed by Terminal.app is just the frontend for the process you choose to run inside of it - in your case, a Unix shell. When you exit the shell, the Terminal.app does not close the window by default, so you have the possibility to inspect the output from whatever command you ran, after it finishes.

You can change your preferences here

Terminal Preferences -> Settings -> Shell:

to either

  1. always close the window, whatever the exit status of the shell was
  2. close the window if the shell exited cleanly
  3. keep the window open (the default)

Besides that, you can (almost) always close windows in OSX with Cmd-W, so you don't need mouse even if it doesn't close automatically.

One more hint: I like hitting Ctrl-D instead of typing exit. Two keys vs. five.


Command + Q -> closes the application/process.

Command + W -> closes window/instance


Yes there is. For example you can use AppleScript to achieve it:

osascript -e 'tell application "Terminal" to close first window'

The first window is always the currently active window. That's the one you want to close.

Before closing the window, the Terminal may ask you, if you really want to close the window. This depends on your settings. You may have chosen to 'close the window only if the shell exited cleanly or no other processes are running apart from …'. (This may be the default setting.) In that case adding & exit to the command closes the window immediately and without asking.

osascript -e 'tell application "Terminal" to close first window' & exit

Actually, for this requirement, you should set some config to your Terminal. follow below instructions and you will close your Terminal just with an exit command.

When the Terminal is up, press +, to open the prefrences window. then you will see below screen:

enter image description here

Then press shell tab and you will see below screen:

enter image description here

Now select Close if the shell exited cleanly for When the shell exits.

Your Terminal is ready for the exit just with an exit command.