与单一的bash线运行在多个终端窗口多个命令 [英] Run multiple commands in multiple Terminal windows with a single bash line

查看:446
本文介绍了与单一的bash线运行在多个终端窗口多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个有趣的问题:使用AppleScript方法以在终端窗口中启动一个新的命令失败,如果终端是忙;更多precisely,它会打开一个新的窗口,但是无法运行该命令。例如,尝试复制+粘贴在这一行:

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

当我运行这个(我对雪豹),我得到三个窗口:首先,命令运行,符合市场预期;但在其他两个,我只是得到一个空的提示。而我得到了所有的三个窗口空的提示,如果我刚刚粘贴命令;显然终端仍忙于处理粘贴操作。

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

我修改您的code一点,以测试它

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

这篇关于与单一的bash线运行在多个终端窗口多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆