Start Terminal in AppleScript

applescriptautomatorsshterminal

At work I'm overseeing several users who use MacBooks to connect to our enterprise environment.

One of our vendors has an old server which users access via ssh. I've created an Automator workflow to launch terminal, set it up the way they like (legacy color scheme and font) and get them to the ssh prompt from the server. I get some unexpected behavior in that when the Automator workflow runs, it opens two Terminal windows, then window I want (ssh client) and then another regular Terminal login.

If the ssh window is closed, Terminal remains open, and the next time the workflow is run, the window isn't visible until the user manually switches to Terminal.

The other peculiarities I'm observing seem to be tied to the fact that the AppleScript spawns two Terminal windows, and then the users simply closing the window rather than quitting Terminal when exiting. Is there a better way to do this? Could I have Terminal quit by default when the "Close Window" button is hit?

Caveats:
This is a controlled environment. I'm pushing my luck with vendor support using Terminal already, they didn't want to support anything other than Linux ssh. 3rd party applications are not acceptable solutions.

Best Answer

You can force Terminal to become frontmost by adding the line:

activate application "Terminal"

into your applescript.

if you launch Terminal with:

tell application "Terminal" to open location "ssh://user@example.com"

then Terminal won't open an extra window.