When I'm done with Terminal, I want to exit it. Right now, I have three options:
killall Terminal. It will end the process, but rather abruptly. I don't think this is the best idea.
Call exit. I've changed the settings so exit closes Terminal. The app still appears open in the Dock though, and doesn't do what I want it to do.
Right click>Quit. However, this isn't a Terminal command to exit it.
So now, what is the way I should exit and close Terminal? I've heard something about osascript but I'm not too sure. I want to exit and close, so that Terminal is no longer open, both as a window and as a process.
In a terminal window, you can type:
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:
I've been using
quit -n terminal
at the end of my scripts. You have to have the terminal set to never prompt in preferences
So Terminal > Preferences > Settings > Shell When the shell exits Close the window Prompt before closing Never
If this is a Mac you type 'exit' then press return.
In the Terminal app, Preference >> Profiles tab.
Select the Shell tab on the right.
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:
Then press shell tab and you will see below screen:
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.osascript -e "tell application \"System Events\" to keystroke \"w\" using command down"
This simulates a CMD + w keypress.
If you want Terminal to quit completely you can use:
osascript -e "tell application \"System Events\" to keystroke \"q\" using command down"
This doesn't give any errors and makes the Terminal stop cleanly.