Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSX - How to auto Close Terminal window after the "exit" command executed.

Tags:

terminal

macos

in Terminal.app

Preferences > Profiles > (Select a Profile) > Shell.

on 'When the shell exits' chosen 'Close the window'


How about the good old Command-Q?


In the Terminal app, Preference >> Profiles tab.

Select the Shell tab on the right. enter image description here

You can choose Never Ask before closing to suppress the warning.


Actually, you should set a config on your Terminal, when your Terminal is up press +, 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.

By the above config each time with exit command the Terminal will close but won't quit.


You could use AppleScript through the osascript command:

osascript -e 'tell application "Terminal" to quit'

In a terminal window, you can type:

kill -9 $(ps -p $PPID -o ppid=)

This will kill the Terminal application process, which is the parent of the parent of the current process, as seen by the kill command.

To close a Terminal window from within a running script, you need to go up one more level in the process hierarchy like this:

kill -9 $(ps -p $(ps -p $PPID -o ppid=) -o ppid=)