I've been trying to figure out how to run a bash command in a new Max OS X Terminal.app 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:
Terminal.app -c "my command here"
But of course this doesn't work. I am aware of the "open -a Terminal.app" command, but I don't see how to forward arguments to the terminal, or even if I did what arguments to use.
You could also invoke the new command feature of Terminal by pressing the
Shift + ⌘ + N
key combination. The command you put into the box will be run in a new Terminal window.In case anyone cares, here's an equivalent for iTerm:
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:
or use applescript:
although you'll either have to escape a lot of double quotes or not be able to use single quotes
I made a function version of Oscar's answer, this one also copies the environment and changes to the appropriate directory
You can use it like this:
or
Here's my awesome script, it creates a new terminal window if needed and switches to the directory Finder is in if Finder is frontmost. It has all the machinery you need to run commands.
I call this script trun. I suggest putting it in a directory in your executable path. Make sure it is executable like this:
Then you can run commands in a new window by just adding trun before them, like this:
Here's the script. It does some fancy things like pass your arguments, change the title bar, clear the screen to remove shell startup clutter, remove its file when its done. By using a unique file for each new window it can be used to create many windows at the same time.