60

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?

migrated from stackoverflow.com Jun 29 '10 at 23:18

This question came from our site for professional and enthusiast programmers.

  • Command + q will close the window – Kolob Canyon Nov 26 '16 at 15:43
80

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.

  • 10
    In Yosemite it's: preferences -> profiles -> shell -> "when the shell exits"... Shell is whichever shell you have selected in General-> On startup open... – cloudsurfin Sep 22 '15 at 17:21
  • Once the shell is exited, is it possible to start a new shell in the same window? If so, how? – Sodved Jul 9 '16 at 2:14
  • @Sodved: I don't think it is, but could be wrong. – Amadan Jul 11 '16 at 5:34
  • This does not answer the question that was asked, as it does not propose a command line operation. – Chris Stratton Jan 4 '17 at 17:59
  • @ChrisStratton You're correct that it does not directly answer the question asked, but it does facilitate the use of the exit command which the OP was using originally. – jdersen Dec 22 '18 at 3:57
18

Command + Q -> closes the application/process.

Command + W -> closes window/instance

  • This does not answer the question that was asked, as it does not propose a command line operation. – Chris Stratton Jan 4 '17 at 17:59
9

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
  • This is almost right, but in actuality the "first window" is not always the one running the command. – Chris Stratton Jan 4 '17 at 18:41
1

I also suggest against the killall suggestion. As suggested modify the settings in your preferences to close window if shell exit was successful. If you're REALLY LAZY (like me), open up your bash profile and add an alias. I have mine set so all I have to do is type 'q'.

0

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.

-2

If you want to terminate the application itself from the commandline:

killall Terminal
  • 4
    that is considered harmful. Apart from the fact tha killall does different things on different Unix versions, it's not nice to kill an application instead of asking it to just quit. – Florenz Kley Nov 15 '12 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy