I use terminal to SSH a lot, however would like the Terminal App to quit when the last Tab closes using exit. I already have the terminal window itself set to close on successful exit, however Terminal keeps running. I followed Ricky Campbell's tutorial here which uses an AppleScript to quit terminal. The AppleScript works perfectly when running outside of Terminal, however I somehow can't get the trap command to work that needs to be placed in the terminal.
For reference I will post the relevant text here:
Now we need a way to kickoff the script. This can be done with the bash command “trap”, having it listen for the EXIT signal. Since I want this to happen everytime my user opens a shell, I add it to my .profile file. I do this with nano:
$ nano ~/.profile
In this file add the following somewhere. You may need to edit the path to the AppleScript file you created earlier:
trap '/usr/bin/osascript $HOME/Scripts/QuitTerminal.scpt' EXIT
All this does is listen for the EXIT signal within bash and when it gets it, runs the script we created earlier.
How do I go about troubleshooting this problem. For some reason the trap is not firing or working the way it should, even after numerous reboots. Is there an alternative way to get the Terminal App to close when the last tab exits?
The links provided by Dori led to the solution. The article suggest that the trap command should be in
.profile, when in fact it has to be placed in
.bashrc. Moving it to the correct script fixed the problem.