Ferdinand
Ferdinand

Reputation: 35

Run a shell script in a new Terminal window from another shell script (OS X)

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

Upvotes: 0

Views: 2265

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207335

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.

Upvotes: 2

Related Questions