Bash Script that will start up second Terminal process?
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.
Solution 1:
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.
Solution 2:
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.