To avoid the Terminal window hanging around, try something like this:
tell application "Terminal"
do script "ssh YOUR PARAMS HERE;exit" in window 1
end tell
or this:
tell application "Terminal"
do script "exec ssh YOUR PARAMS HERE" in window 1
end tell
The “;exit” tells the shell to exit after the preceding command has finished.
The exec basically tells the shell to make the execd command its last command. In technical terms, the shell skips the fork of the standard fork+exec process launching system call duo. The execd process replaces the shell process. It inherits the shells PID. So anything waiting for the original shell process to exit will end up waiting for the shh process to exit instead (because the shell process was wholly replaced by the ssh process).
For this to be an appropriate technique, you will have to be able to decide that shh (or other command line program) is the last command you want to run in that window before it is time to start that command. If you are only ever running that one ssh command, then this condition has already been met. Something that would be more problematic would be a situation where you can only decide whether you need to run another command in that Terminal window based on the output of the current command.
If you are using “compound” shell commands (multiple commands indicated by parenthesis, curly braces, semicolons, pipes (vertical bars), double ampersands, loops or conditionals, etc.) in your do script command to Terminal, then you cannot put exec directly in front of it. Instead you would need to put the exec directly in front of only the last command to be run. Exactly how to do this depends on which type of compound command you are using. In this situation, it would probably be better just to append “;exit”, like in the first method.
The main difference between the two techniques is that with exit, the shell process hangs around until after the shh process has exited when it then processes the exit command and exits itself. For exec the shell process is replaced with the ssh process. The exec-based replacement is a bit more efficient, but harder to use correctly. The efficiency gains are probably not enough to worry around.
Terminal “busy” adjustment
It appears that part of the determination of the value of the busy property of a Terminal window is based on the settings in the “Processes” section of the Terminal Inspector window (Command-I or File > Show Info). ssh is in the default list of processes that are checked when closing a Terminal window. When I took ssh out of the list, in addition to enabling the prompt when closing the window, it also made the busy property return true while ssh was running. The change in the list of processes seems to have an effect on the busy status even if the prompt-before-closing setting is configured to ignore the list (always prompt or never prompt).
Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari 3.0.4 (523.12)
Operating System: Mac OS X (10.4)