几乎所有(每个?)osx 程序都可以使用以下命令从命令行启动:
appName.app/Contents/MacOS/command
对于终端,命令是:
/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal
您可以使用自动完成(制表符)或 ls 来查找正确的文件名。 “.app”基本上是一个文件夹。
要更改颜色并运行脚本...我认为您不能使用 shell 脚本来执行此操作,因为终端不接受参数(“终端 myScript.sh”不启动 myScript)。使用 iTerm 即可。
解决方法是使用 applescript(包装在 shell 脚本中):
#!/bin/sh
osascript -e '
tell application "Terminal"
activate
tell window 1
do script "sleep 5; exit"
set background color to {0, 11111, 11111}
set win_id to id
end tell
set w_ids to (id of every window)
repeat while w_ids contains win_id
delay 1
set w_ids to (id of every window)
end repeat
end tell'
好的,现在它的行为应该与 xterm 示例完全相同。缺点是不断轮询窗口 id(这是不好的编程)。
编辑: 更优雅的applescript 将使用终端的'busy' 属性。我将保留原始代码原样用于一般程序(不仅仅是终端)。
tell application "Terminal"
tell window 1
do script "sleep 2"
set background color to {0, 11111, 11111}
repeat while busy
delay 1
end repeat
close
end tell
end tell
同样对于完全正确的程序,应该检查终端是否正在运行。它会影响打开的窗口数量。所以,这应该首先运行(又是一个看起来很讨厌的 hack,我稍后会在找到工作解决方案时对其进行编辑)。
tell application "System Events"
if (count (processes whose name is "Terminal")) is 0 then
tell application "Terminal"
tell window 1
close
end tell
end tell
end if
end tell
br,
朱哈