How to close the Terminal automatically on macOS
If you are a regular user of the shell script on macOS you will notice that after completing the process it does not automatically close the Terminal, but the user must turn it off manually. Therefore this article will show you how to close the Terminal automatically after completing the process.
This method only works when you launch the shell script outside bash such as clicking on it on the Finder or setting a custom hotkey to open the program. If not, you will be taken back to the Command Prompt. You can use the killall Terminal command to close the Terminal application from the script but it will close all open Terminal windows.
- How to customize Terminal on Mac
- 5 best alternatives for Terminal application on macOS
- Use commands and some tips for Mac OS X
Change behavior from Profile settings
Open the Terminal application from Dock or the Applications folder, then open the installation by pressing Command + Comma .
In the Settings window, go to the Profiles tab. Here, the default profile is always selected. In the settings on the right, click on the Shell tab and then click on the drop down menu When the shell exits .
By default, the option Don't close the window is selected, but you can change it to Close if the shell exited cleanly .
You can close this Terminal window all the time, but will receive an error message if the exit process is in non-zero exit status. Note, you need to exit the script with the exit command so that this behavior works at all times.
If launched from the Finder, the exit command will automatically add to the script.
Use iTerm
- https://www.iterm2.com/
iTerm2 is a popular Terminal replacement application for macOS, which automatically closes the window when the shell script exits. If you have used iTerm as the default Terminal, you can see that the shell script starting from the Finder remains open with the original Terminal application. So you still have this problem unless you have set it to open with iTerm.
You can change the application to open the script by right-clicking the script in the Finder and then selecting Get Info .
You will see a drop down menu to change the script open application, select iTerm and click Change All to apply changes to the scripts.
By default, if you open the iTerm window, it will launch in a separate tab, not a separate window, and the tab will close automatically when the process is complete.
I wish you all success!
You should read it
- 6 interesting terminal commands on Mac
- 5 best alternatives for Terminal application on macOS
- Windows Terminal can now automatically launch configurations as administrator
- How to use Terminal on a Mac
- How to customize Windows Terminal application
- Notable changes in Windows Terminal ver 0.11
- 8 best free Terminal Emulator apps for Android
- How to make Windows Terminal the default Terminal application and its benefits
- How to fix the problem of being unable to enter Terminal in Linux
- Top 5 useful Terminal tips for Mac users
- How to install Hyper Terminal in Ubuntu 20.04
- How to customize Terminal on Mac