4

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.

  • 1
    Do you really need a terminal window for the second process? If not, would running the server script as run-server & be enough? – nohillside Sep 28 '13 at 9:11
  • Tab, instance, whatever you want to call it. Yes, I need it. – Danijel-James W Sep 28 '13 at 9:39
4

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.

  • Thank you, I don't know how I overlooked this. I have been trying different things for the past week, and this does exactly what I want it to do. Thank you. – Danijel-James W Sep 28 '13 at 9:39
1

Building on the previous answer, you can use the do script to run a second Terminal window and then even issue multiple commands sequentially using -e

osascript -e 'tell app "Terminal" to do script "uptime"' -e 'tell app "Finder" to delete file "filename" on Desktop'

So this way you can specify multiple actions in sequence too using only 1 line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .