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

发布于 2024-09-09 07:25:14 字数 738 浏览 7 评论 0原文

这是一个有趣的问题:使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

脱离于你 2024-09-16 07:25:14

您正在运行的实际脚本是什么

我稍微修改了您的代码来测试它

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

,这似乎工作正常

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文