Starting Terminal from CLI

jasonvp

Registered
Greetings -

I run OpenMenu so that I can get a pop-up menu when I right-click anywhere in the background. It allows me to start applications quickly and easily; very X11-ish. From that menu, I run scripts that pop open xterms that ssh to other hosts.

I'd like to use another terminal app, like the one included with OS X. I can't figure out how to open Terminal from the CLI. Is it possible? I know the 'open' command will do it, but it'll only open the first one. I need a way, from the CLI, to open new Terminal windows and automatically run commands within them.

Is it possible to do this?

Thanks!

jas
 
Jas,

You can open terminal by running the command (not surprisingly):

Code:
open /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal

Your best bet: an apple script that contains the lines

Code:
tell application "Terminal"
	do script "command"
end tell

where "command" is something like "ps -aux | grep monkey". Also you can have this call a shell script, if that is more familiar to you. Just use the script editor or your favorite text editor to dream up whatever you want. You can run that applescript you created from CLI using:

Code:
osascript scriptname

Good luck,
Graham
 
Graham -

Fragger said:
Jas,
You can open terminal by running the command (not surprisingly):

Won't this only open the *first* Terminal window? I've tried this a few times and it does nothing if I already have a Terminal window open. Perhaps there's an arg I can throw to open that says "Open *another* copy of this?"

Thanks!

jas
 
You are correct that would only open the first window, but the subsequent commands I gave you will open a new window for each time you run them. If you run
Code:
do script ""
as is, with nothing between the quotes, it will simply spawn a new window (ugly, yes.)

Hopefully the helps,
graham
 
Fragger said:
You are correct that would only open the first window, but the subsequent commands I gave you will open a new window for each time you run them.

Way friggen cool. Thanks! Just what I was looking for.

jas
 
OK, follow-up question. I've whipped up a few AppleScripts to do exactly what I want, and they work great. Now: can I use the same scripts the set the title of each individual Terminal.app window?

For instance, I tried this in the script I use to just open a new Terminal (no command)
Code:
tell application "Terminal"
	do script ""
	set title of window to "test"
end tell

But it tells me it can't set the title of window to "test". I'm missing some other step or key here...

Thanks.

jas
 
Back
Top