MacOS – Bash Script that will start up second Terminal process

applescriptbashmacosterminal

I need a script that will be able to fire up a second Terminal instance and pass a command directly to that one whilst it continues it's own executions.

It's to start up Python script that will host a server whilst the main instance of Terminal would continue to run it's series of executions over a period of 30 seconds (for example) then it would be able to kill the PID of the Python script and kill that secondary Terminal process and continue until it's finished.

Does anybody have an idea of how to do this? Coming from Windows, it would be very easy to get a BAT file to execute a second BAT file in it's own environment and then kill it at a later stage.

Best Answer

You can use the do script AppleScript command to run a command in a new Terminal window:

osascript -e 'tell app "Terminal" to do script "uptime"'

It doesn't start a second process or instance for Terminal though. On OS X there is typically only one instance for each application, even though you can use open -n to open another instance.