Running a command in a new Mac OS X Terminal window


I've been trying to figure out how to run a bash command in a new Max OS X window. As, an example, here's how I would run my command in a new bash process:

bash -c "my command here"

But this reuses the existing terminal window instead of creating a new one. I want something like: -c "my command here"

But of course this doesn't work. I am aware of the "open -a" command, but I don't see how to forward arguments to the terminal, or even if I did what arguments to use.

10/25/2018 5:49:12 PM

Accepted Answer

one way I can think to do it off the top of my head is to create a .command file and run it like so:

echo echo hello > sayhi.command; chmod +x sayhi.command; open sayhi.command

or use applescript:

osascript -e 'tell application "Terminal" to do script "echo hello"'

although you'll either have to escape a lot of double quotes or not be able to use single quotes

6/12/2009 10:28:48 PM

Partial solution:

Put the things you want done in a shell-script, like so

echo "yey!"

And don't forget to 'chmod +x file' to make it executable. Then you can

open -a scriptfile

and it will run in a new window. Add 'bash' at the end of the script to keep the new session from exiting. (Although you might have to figure out how to load the users rc-files and stuff..)

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow