2

I want to open new terminal and pass some values on OSX. I tried this code:

open_new_terminals_automatically()
{
    osascript -e 'tell application "Terminal" to do script "cd $1; $2"'
}

# call the function and pass arguments
open_new_terminals_automatically "/root/var/fome_path" "some_commnds -argument"

This is very simple example to explain what I want to do. How I can implement it to run as bash script on OS X.

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

1 Answers1

2

What you have almost works, except you need double quotes instead of single quotes for the variable expansion to work properly.

Just create a script run.sh with contents

osascript -e "tell application \"Terminal\" to do script \"cd $1; $2\""

Then you can call it with sh run.sh "/root/var/fome_path" "some_commnds -argument".

If you want this all done in one script, then just do

open_new_terminals_automatically()
{
    osascript -e "tell application \"Terminal\" to do script \"cd $1; $2\""
}

# call the function and pass arguments
open_new_terminals_automatically "/root/var/fome_path" "some_commnds -argument"
Iluvatar
  • 1,537
  • 12
  • 13