Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically launch Terminal.app with a specified command (and custom colors)

I can launch an xterm from the command line (or a program, via a system call) like so:

/usr/X11/bin/xterm -fg SkyBlue -bg black -e myscript 

That will launch an xterm with blue text and a black background, and run an arbitrary script inside it.

My question: How do I do the equivalent with Terminal.app?

like image 838
dreeves Avatar asked Dec 09 '10 23:12

dreeves


1 Answers

You can open an app by bundle id too, and give other parameters.

If there's an executable script test.sh in the current directory, the following command will open and run it in Terminal.app

 open -b com.apple.terminal test.sh  

The only down side that I can find is that Terminal doesn't appear to inherit your current environment, so you'll have to arrange another way to pass parameters through to the script that you want to run. I guess building the script on the fly to embed the parameters would be one approach (taking into account the security implications of course...)

like image 60
Sam Deane Avatar answered Nov 03 '22 12:11

Sam Deane