0

I routinely open a lot of Terminal windows each with an ssh session. To streamline the process I have a series of shell scripts that look like this:

#!/bin/sh
osascript <<EOS
tell application "Terminal"
    activate
    do script "set_background_color salmon; ssh alan@demo.znyx.com"
end tell
EOS

This works. I can either execute the script from a shell prompt or click it in the Finder window. (To do this the file name suffix is .command instead of .sh)

The problem is that when I execute it from Finder, I end up with a dead window ("Process Completed") behind the window I intended to open. Is there any way to get rid of it or not have it open in the first place?

UPDATE:

The solution in this other question results in dialog boxes appearing that provide confirm/review/cancel options. This is undesirable.

Community
  • 1
  • 1
AlanObject
  • 9,613
  • 19
  • 86
  • 142
  • Possible duplicate of [How do I get a Mac ".command" file to automatically quit after running a shell script?](http://stackoverflow.com/questions/2565944/how-do-i-get-a-mac-command-file-to-automatically-quit-after-running-a-shell-s) – Alexander O'Mara Oct 02 '16 at 00:28
  • @AlexanderO'Mara The solution in that other question doesn't work for me. Every variation I try causes a dialog box to pop up to confirm closing this or other window. – AlanObject Oct 02 '16 at 01:04

1 Answers1

1

When you double-click a .command file, the file is passed to Terminal and Terminal creates a window and executes the commands within it. The commands in your .command file use AppleScript to tell Terminal to run a command in yet another window.

Why not remove the middle man and just put the ultimate commands you want to run — set_background_color salmon; ssh alan@demo.znyx.com — in the .command file? Drop that stuff with running an AppleScript. In other words, the contents of your .command file should just be:

set_background_color salmon
ssh alan@demo.znyx.com

Alternatively, you could take the AppleScript from your .command file (the part between <<EOS and EOS), put it into Script Editor.app, and save it as an applet.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • Your answer works well enough (simpler is better!) that it is what I will use for now. The reason I was trying to use Applescript is that I wanted to ultimately open windows programmatically -- one click to open a full set of any number similar to the "Open Window Group" menu option except with the connections already made. That can wait for later though. – AlanObject Oct 02 '16 at 16:10