Updated from another editor
Saved
# Terminal: Quit Automatically Create a new text file in your home folder named `autoQuitTerminal.scpt`: ```applescript tell application "Terminal" # If there is only one tab remaining, and it contains the word "logout" then this is the final window if (count of (tabs of (every window whose visible is true))) = 1 then try set theContents to words of ((contents of tab 1 of window 1) as Unicode text) set exitLastTab to (theContents contains "logout") on error set exitLastTab to false end try if exitLastTab is true then quit end if else if (count of (tabs of (every window whose visible is true))) < 1 then # If no window remains open, then obviously we can quit the app. # This would occur when the final window is closed without ‘exit’ quit end if end tell ``` Make the file executable by running: ```bash chmod u+x $HOME/autoQuitTerminal.scpt ``` At the end of the file `~/.bash_profile` add the following paragraph: ```bash #auto-closing Terminal app on last window if [ "$TERM_PROGRAM" == "Apple_Terminal" ] && [ -x $HOME/autoQuitTerminal.scpt ]; then trap '/usr/bin/osascript $HOME/autoQuitTerminal.scpt' EXIT fi ``` In Terminal, go into Preferences and modify the following settings accordingly: ``` Terminal > Preferences > Shell: * “When the shell exits” * Close if the shell exited cleanly * “Prompt before closing” * Only if there are processes other than ``` Quit Terminal. > If all goes well, and you don't have any other scripts or jobs running in the background, from now on Terminal should quit itself automatically whenever you close the last of its windows.
Password
Cancel
Encrypt