-1

I have a current perl script that I was executing on a windows machine in cygwin, that was opening a new cygwin terminal window and ssh'ing into a remote machine.

Trying to duplicate the mintty command on mac.

if ($noexec) {
    system("echo mintty -s 160,40 $cursor -o 
    BackgroundColour=$color -o 
    Title='\"$title\"' -e ssh $url \&");
} else {
    system("mintty -s 160,40 $cursor -o BackgroundColour=$color -o 
    Title=\"$title\" -e ssh $url \&");
}
  • "Duplicate" how? Do you have a command named `mintty` or are you trying to ask what to replace it with? – tripleee Jun 11 '19 at 17:19
  • Sorry, trying to replace current mintty command that works on windows with cygwin with applicable mac terminal command. – Michael McCarthy Jun 11 '19 at 17:22
  • The Mac Terminal is `/Applications/Terminal.app` but you probably don't need to open a separate window; just run your script in an existing Terminal window if that's what you want. – tripleee Jun 11 '19 at 17:23
  • Possible duplicate of [Running a command in a new Mac OS X Terminal window](https://stackoverflow.com/questions/989349/running-a-command-in-a-new-mac-os-x-terminal-window) – tripleee Jun 11 '19 at 17:24
  • The script is used to launch multiple sessions, so want a new window with each execution. – Michael McCarthy Jun 11 '19 at 17:27
  • suggested page does not answer specific requirement stated here. – Michael McCarthy Jun 11 '19 at 17:42
  • How so? Both `open Terminal command` and `osascript "tell Terminal..."` should fulfill your stated requirements. – tripleee Jun 11 '19 at 17:49
  • @tripleee because I can't get these commands to execute inside the perl script – Michael McCarthy Jun 13 '19 at 18:32
  • At least `perl -e 'system("open -a Terminal.all /tmp/testing")'` works for me when `/tmp/testing` is an executable shell script. Are you omitting something from the question or can you reproduce this? Do you need instructions for how to write a temporary shell script to a file? – tripleee Jun 18 '19 at 06:44
  • @triplee I feel like all the information is provided here. The script is a perl script so perl command is not needed. See code snippet. The perl script launches a new terminal window on windows and executes ssh command. Trying to do that on Mac. I don't want to call another script, but that may be what I have to do. I just want to open -a Terminal.all and pass it ssh command and url variable not another file/script. – Michael McCarthy Jun 18 '19 at 16:40
  • The explicit `perl` command is just to show you what exactly I did. If your script does something fundamentally different then that is information which should be explained in more detail in the question; if not, I have showed you exactly how to solve the problem in your script. The `osascript` solution doesn't require the commands to be in a separate script file so maybe go with that (and there may be a separate convenient Perl binding so you don't have to go through `os.system()`. – tripleee Jun 18 '19 at 17:08
  • But so this still seems to me like you should accept the proposed duplicate, or explain in more detail how the answers there are unsuitable. – tripleee Jun 18 '19 at 17:09
  • @tripleee this is not a duplicate because I am asking specifically how to replace the code above to open a new terminal and pass it an ssh command from a perl script on a mac. The script code above works on a windows machine. Any answer not addressing the specific question is not helpful to me. I appreciate you trying to help, but showing what you did when it's different than what I am asking is not helpful. I apologize if I am not being clear in my ask, but I feel like I spelled it out. – Michael McCarthy Jun 18 '19 at 19:18

1 Answers1

1

Here is a simple translation of your code to use Applescript to perform the task, as explained in the proposed duplicate Running a command in a new Mac OS X Terminal window

if ($noexec) {
    system(qq{echo osascript -e 'tell application "Terminal" to do script "ssh $url \& "'});
} else {
    system(qq{osascript -e 'tell application "Terminal" to do script "ssh $url \& "'});
}

Running the ssh command in the background seems like a very odd thing to do. Probably you should replace \& with ; exit.

I'm not sure what the mintty options mean (I guess set the geometry to 160x40 and pick a particular cursor?) so I haven't attempted to implement those. https://superuser.com/questions/1188772/mac-command-to-change-the-background-color-in-a-terminal shows how to set the background color in Terminal via Applescript, for example.

If mintty or Windows ssh really accepts a URL to connect to (something like ssh://username@hostname perhaps?) you will have to pick it apart and extract only the parameters which are acceptable to U*x ssh (like username@hostname without the ssh:// protocol specifier).

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • https://apple.stackexchange.com/questions/18727/problem-setting-terminal-window-bounds-with-applescript explores setting a Terminal window's dimensions from Applescript. – tripleee Jun 19 '19 at 04:59
  • There may be Perl-native solutions which allow you to bypass the `system()` call and provide better Applescript integration. https://metacpan.org/pod/Mac::OSA::Simple looks like a simple way to do that but I have no idea if it's current and supported. – tripleee Jun 19 '19 at 05:09