0

How can I make a shell script open multiple new Terminal windows that executes each their shell script? Just like asked here, but in OS X.

I've got a for-each loop which runs trough all the given arguments and should execute a script in a new Terminal window for each given argument (and pass on the argument).

This is what I've tried:

#!/bin/bash

for arg in $@ do

  open -a Terminal ./somescript.sh --args $arg

done
Community
  • 1
  • 1
Ferdinand
  • 35
  • 6
  • Have you looked at this? http://stackoverflow.com/questions/4404242/programmatically-launch-terminal-app-with-a-specified-command-and-custom-colors – d3v_1 Sep 09 '16 at 14:52

1 Answers1

2

I think you mean this:

#!/bin/bash
for arg in "$@"; do
  osascript <<EOF
tell application "Terminal" to do script "echo \"$arg\""
EOF
done

Then run:

chmod +x aboveScript
./aboveScript a b "cd ef"

If you like that, change the echo to ./somescript.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Is it possible to achieve without osascript? I'm supposed to just use bash. I've got it working in Linux by writing `gnome-terminal -x somescript.sh $arg` and hoped to find something similar for OS X. – Ferdinand Sep 09 '16 at 16:05
  • If you install `XQuartz` (X11 Windows for OSX) you can run `xterm -e "..."` just as on Linux. – Mark Setchell Sep 09 '16 at 16:07