[X-Unix] Quit Terminal on exit

Rob Griffiths robg at macosxhints.com
Fri Mar 12 17:25:52 PST 2004


On Mar 12, 2004, at 4:24 PM, Marley Graham wrote:

> solution would, obviously close all Terminal windows as a result of 
> quitting Terminal. I recognize the potential hazard, but for the users 
> I have in mind, there is no valid reason for them to have other 
> Terminal windows open.

OK, here's a theoretical solution along with a *really* ugly 
AppleScript (I am NOT an AppleScript coder in any manner!).

1) Set up the Terminal to launch a shell script via the Prefs
2) In that shell script, the first line launches an AppleScript
3) The second line runs the ssh; exit command you already have.

My bad version of the AppleScript looks like this:

repeat
   try
     tell application "Terminal"
       tell window 1
         get name
       end tell
     end tell
   on error error_message
     tell application "Terminal"
       activate
       quit
     end tell
     exit repeat
   end try
end repeat

This script basically gets a meaningless property from the Terminal -- 
the name of the window. It does so repeatedly until the window is 
closed, at which point it errors out and activates the error loop. In 
the error loop, Terminal is quit and the repeat loop exits, ending the 
script.

Things that I know are *really* wrong with this:
  - I think it should be possible to only poll every "X" seconds to see 
if a window is open. Right now, this thing is probably very CPU 
intensive.
  - It might even be possible to just check "Is there a terminal window 
open?" instead of my getting of a name variable
  - Right now, I get an error (connection invalid) when I try this as an 
app from the Finder, but it does quit the Terminal when you close the 
last open window.
  - Did I mention I'm not an AppleScripter? :)

In any event, a much neater version of the above, if executed as an 
application before the ssh command, should (might?) quit the Terminal 
when the window closes ... maybe :).

-rob.



More information about the X-Unix mailing list