Macos 使用单个bash行在多个终端窗口中运行多个命令

Macos 使用单个bash行在多个终端窗口中运行多个命令,macos,bash,terminal,applescript,Macos,Bash,Terminal,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

这里有一个有趣的问题:如果终端“忙”,则在终端窗口中使用启动新命令失败;更准确地说,它将打开一个新窗口,但无法运行该命令。例如,尝试在以下位置复制并粘贴此行:

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"';
当我运行这个(我在雪豹上)时,我得到三个窗口:在第一个窗口中,正如预期的那样运行命令
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"';

这似乎很好

我第一次运行脚本时,前两个终端窗口冻结,只有第三个窗口运行脚本。第二次,第一扇窗户跑了,另外两扇窗户都冻住了。(所谓“冻结”,我的意思是它们没有执行任何操作,我无法在其中输入文本,这与我以前遇到的问题相同。)因此,可能是我的设置有点奇怪。确认:我注释掉了我的
.bashrc
,一切正常。所以现在我只需要找出是什么导致了那里的问题。谢谢