Tag Archives: Terminal

Quit Terminal.app after closing last window

I use Terminal.app on a daily basis, mostly for my research as I am currently building an adjoint of the CMAQ model.  I like to have 4+ windows open at all times while working in Terminal, as it allows me to watch the progress of a simulation while also editing files, compiling, etc.  I have macros setup that will log me into and out of each terminal window.  One of the frustrating things that I ran into was that, after the macro logged me out of the final window, I wanted the Terminal application to quit.  Now, I very easily could have added the Quit Application command to the macro, however I was hoping for a solution that would also work even if the macro wasn’t called.  I surfed the web for a while and found nothing, until I got a response on my post on Apple’s forums.

I am copying te response to this website, however all credit for the material goes to François J. Perreault, who answered the question.

Here’s how to have Terminal quit automatically after closing all your shells:

  1. Create a new text file in your home folder named “autoQuitTerminal.scpt“:
    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

    Continue reading Quit Terminal.app after closing last window

Creating Workspaces in Terminal

If you have read some of my other posts, you know that I like to have multiple terminal windows open whenever I am working.  This used to involve opening the Terminal app, and then opening multiple more windows.  Then I had to drag each window into the location that I wanted it to be at.  I later realized that I could have the Terminal app save my open windows as a Workspace, and could define a default workspace to be opened whenever Terminal is opened.

This is rather simple to do, and can be accomplished by following the steps below: Continue reading Creating Workspaces in Terminal

Mac OS X Quit Application from Command Line

When doing any type of programming or scripting, I do my best to streamline everything (see this post and this post).  Basically anything I do in the Terminal that can be automated, I try to automate.  In addition to the posts linked above, I also have macros set up to login me into the supercomputer that I do most of my research on.

When I first open Terminal, I have it set to open 4 Terminal windows in specified locations.  For those of you who don’t know how to do this, I will soon be providing a post detailing the necessary steps to accomplish this.

Continue reading Mac OS X Quit Application from Command Line