1

In Windows, I can run any program from the command prompt by typing

c:> start startup.sh

and windows will run the startup.sh in a different command prompt(terminal) window.

How can I do the same in the mac(linux bash) so that the startup.sh script runs in
1) a different terminal window ?
2) a different terminal tab ?

update : As mentioned, I'm looking to start a program(such as mc) or a shellscript in another tab or window -- not just a shellscript.

1

You can launch a script in a new Terminal instance with:

open -b com.apple.terminal test.sh

where test.sh is the name of the script you want to run.

Source


@anjanbecchu found the following script:

TAB_NAME=$1; COMMAND=$2; osascript -e "tell application \"Terminal\"" -e "tell application \"System Events\" to keystroke \"t\" using {command down}" -e "do script \"printf '\\\e]1;$TAB_NAME\\\a'; $COMMAND\" in front window" -e "end tell" > /dev/null
  • when I tried this command for starting a shell script, it works; However, when I tried to use the same command for starting midnight commander(mc), it's assuming that mc resides in the current directory. I don't want to type mc's full path. Is there a way that it uses the $PATH to find what I want ? Also, what is the way to run the shellscript/program in another tab ? – anjanbacchu Sep 5 '14 at 4:06
  • @anjanbacchu I don't think you can run it in another tab. The problem is that there is no easy way to talk to the currently rubbing Terminal application from the command line. Even the above doesn't talk to it directly - it uses the OS's open filetype mechanism, similar to if you had double-clicked on the file. The way the commandline works on Windows is very different than on *nix (OS X, Linux), which makes what you want to do very difficult. – Darth Android Sep 5 '14 at 14:30
  • I found a script on the net that can do what I was looking for. Here's the shell function.TAB_NAME=$1; COMMAND=$2; osascript -e "tell application \"Terminal\"" -e "tell application \"System Events\" to keystroke \"t\" using {command down}" -e "do script \"printf '\\\e]1;$TAB_NAME\\\a'; $COMMAND\" in front window" -e "end tell" > /dev/null – anjanbacchu Sep 7 '14 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.