使用单个 bash 行在多个终端窗口中运行多个命令 [英] Run multiple commands in multiple Terminal windows with a single bash line
问题描述
这是一个有趣的问题:使用 AppleScript 方法 如果终端忙",则在终端窗口中启动新命令失败;更准确地说,它将打开一个新窗口,但无法运行该命令.例如,尝试复制+粘贴这一行:
Here's an interesting problem: Using the AppleScript method to launch a new command in a Terminal window fails if Terminal is "busy"; 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"';
当我运行它时(我在 Snow Leopard 上),我得到三个窗口: 在第一个窗口中,命令 foo
按预期运行;但在另外两个中,我只得到一个空提示.如果我刚刚粘贴了命令,我在所有三个窗口中都会得到空提示;显然终端仍在忙于处理粘贴"操作.
When I run this (I'm on Snow Leopard), I get three windows: In the first, the command foo
is run, as expected; 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.
现在,AppleScript 可能不是执行此操作的最佳方式,但我真的想编写一个脚本,按顺序启动一堆终端窗口,并在每个窗口中运行一个命令.也许最好的方法是使用 bash 脚本.只要我能为它创建一个别名,我就很高兴.那么如何做到这一点?
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. Maybe the best way to do that is with a bash script. 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"';
这似乎工作正常
这篇关于使用单个 bash 行在多个终端窗口中运行多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!