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
1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
If you install XQuartz (X11 Windows for OSX) you can run xterm -e "..." just as on Linux.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.