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

后端 未结 6 728
夕颜
夕颜 2020-12-08 01:03

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

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 01:18

    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...)

提交回复
热议问题