简体   繁体   English

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

[英]Run multiple commands in multiple Terminal windows with a single bash line

Here's an interesting problem: Using the AppleScript method to launch a new command in a Terminal window fails if Terminal is "busy"; 这是一个有趣的问题:如果终端“忙”,使用AppleScript方法在“终端”窗口中启动新命令将失败。 more precisely, it will open a new window but fail to run the command. 更确切地说,它将打开一个新窗口,但无法运行该命令。 For example, try copy+pasting this line in: 例如,尝试复制并粘贴以下行:

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"';

When I run this (I'm on Snow Leopard), I get three windows: In the first, the command foo is run, as expected; 当我运行它时(我在Snow Leopard上),我得到三个窗口:在第一个窗口中,按预期运行foo命令; but in the other two, I just get an empty prompt. 但在另外两个中,我只是得到一个空提示。 And I get empty prompts in all three windows if I've just pasted the command in; 如果我刚刚将命令粘贴到其中,则在所有三个窗口中都会得到空提示; apparently Terminal is still busy processing the "paste" operation. 显然,终端仍在忙于处理“粘贴”操作。

Now, AppleScript might not be the best way of doing this, but I really want to write a script that launches a bunch of Terminal windows, in order, and runs a command in each. 现在,AppleScript可能不是执行此操作的最佳方法,但我确实想编写一个脚本,该脚本依次启动一堆终端窗口,并在每个终端窗口中运行一个命令。 Maybe the best way to do that is with a bash script. 也许最好的方法是使用bash脚本。 As long as I can create an alias to it, I'm happy. 只要我可以为其创建别名,我就很高兴。 So how to do this? 那么该怎么做呢?

what are the actual scripts you are running 您正在运行的实际脚本是什么

I modified your code alittle to test it 我修改了所有代码以对其进行测试

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"';

and this seems to work fine 这似乎很好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM