OSX shell脚本打开新的终端窗口并运行程序

时间:2013-11-06 17:17:39

标签: linux macos bash shell

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

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

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

谁能告诉我怎么做?在一个完美的世界里,我也喜欢这个脚本在Linux上运行,所以如果有一个可移植的方法,那就更好了。

谢谢!

2 个答案:

答案 0 :(得分:5)

do script命令在新的终端窗口中运行命令:

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

答案 1 :(得分:0)

类似的东西:

 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
相关问题