![](/img/trans.png)
[英]Bash osascript(AppleScript) in mac terminal, run multiple commands sequentially
[英]Run multiple commands in multiple Terminal windows with a single bash line
这是一个有趣的问题:如果终端“忙”,使用AppleScript方法在“终端”窗口中启动新命令将失败。 更确切地说,它将打开一个新窗口,但无法运行该命令。 例如,尝试复制并粘贴以下行:
osascript -e 'tell application "Terminal" to do script "foo"'; osascript -e 'tell application "Terminal" to do script "bar"'; osascript -e 'tell application "Terminal" to do script "baz"';
当我运行它时(我在Snow Leopard上),我得到三个窗口:在第一个窗口中,按预期运行foo
命令; 但在另外两个中,我只是得到一个空提示。 如果我刚刚将命令粘贴到其中,则在所有三个窗口中都会得到空提示; 显然,终端仍在忙于处理“粘贴”操作。
现在,AppleScript可能不是执行此操作的最佳方法,但我确实想编写一个脚本,该脚本依次启动一堆终端窗口,并在每个终端窗口中运行一个命令。 也许最好的方法是使用bash脚本。 只要我可以为其创建别名,我就很高兴。 那么该怎么做呢?
您正在运行的实际脚本是什么
我修改了所有代码以对其进行测试
osascript -e 'tell application "Terminal" to do script "cd Desktop"'; osascript -e 'tell application "Terminal" to do script "cd .."'; osascript -e 'tell application "Terminal" to do script "ls"';
这似乎很好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.