在OSX系统中,如何编写一个shell脚本来打开新的终端窗口并运行程序?

4

我正在尝试编写一个简短的shell脚本来打开一个新的终端窗口并启动一个程序。以下是我的脚本:

osascript <<END
tell application "Terminal"
    make new window
    activate
    set contents of window to "./hello" & return
end tell
END

执行错误:终端遇到错误:AppleEvent 处理程序失败。 (-10000)

有人能告诉我如何解决吗?在完美的情况下,我也希望此脚本能够在Linux上运行,所以如果有一种可移植的方法,那将是更好的选择。

谢谢!

2个回答

5
< p > < code > do script 命令在新的 Terminal 窗口中运行命令:

osascript -e 'tell app "Terminal" to do script "uptime"'

1
像这样的东西:
 osascript<<EOF
tell application "System Events"
  tell process "Terminal" to keystroke "t" using command down
end
tell application "Terminal"
  activate
  do script with command "./hello" in window 1
end tell
EOF

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接