使用单个 bash 行在多个终端窗口中运行多个命令
这是一个有趣的问题:使用 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
;在第一个窗口中,按预期运行命令 foo
;但在另外两个中,我只得到一个空提示。如果我刚刚粘贴命令,我会在所有三个窗口中收到空提示;显然终端仍在忙于处理“粘贴”操作。
现在,AppleScript 可能不是执行此操作的最佳方法,但我真的想编写一个脚本来按顺序启动一堆终端窗口,并在每个窗口中运行一个命令。也许最好的方法是使用 bash 脚本。只要我能为它创建一个别名,我就很高兴。那么如何做到这一点呢?
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在运行的实际脚本是什么
我稍微修改了您的代码来测试它
,这似乎工作正常
what are the actual scripts you are running
I modified your code alittle to test it
and this seems to work fine