close tab/window in terminal app

hi there

when executing a shell script in terminal

set myTab to do script ""

i get back the tab of that window. how do i close that tab/window then?

close myTab 

gives an error.

from the result of myTab
tab 1 of window id 1061 of application “Terminal”
i somehow have to go back to its window and i guess i can close then that. but how do i do that?

thanks heaps, olli

This works for me (combining this query with your other post about the tab’s busy state):

set theCommand to ""

tell application "Terminal"
	set myTab to do script theCommand
	repeat until (myTab's history contains theCommand)
		delay 1
	end repeat
	repeat while (myTab's busy)
		delay 1
	end repeat
	(* do script "exit" in myTab
	repeat until (myTab's history contains "[Process completed]")
		delay 1
	end repeat *)
	close (first window whose selected tab is myTab) saving no
end tell

Edit: After my original reply, I discovered that the new terminal window was sometimes opening and closing again immediately with nothing happening in between. Apparently there’s a brief instant after it opens when the tab isn’t busy because it hasn’t started running yet! I’ve got round this by waiting for the tab’s history to contain the command to be executed before checking the busy status, but if anyone knows a better way, please chime in.

If the idea’s just to prevent a proliferation of windows, and you don’t mind using the one that’s currently open, you could do this:

tell application "Terminal"
	do script "'" in front window
end tell