gpt4 book ai didi

docker - 我可以强制applescript同步运行吗?

转载 作者:行者123 更新时间:2023-12-01 14:47:09 24 4
gpt4 key购买 nike

我正在为 iTerm2 编写一个简单的 applescript 脚本,它生成一堆选项卡并开始在其中运行服务(我有很多微服务,并且所有微服务都需要运行以在本地进行测试)。

事情大部分都在工作,但是我遇到了一些有点奇怪的行为,我认为这与早期的 applescript 发送命令有关。我们来看一个具体的例子:

create tab with default profile   
tell the current session
write text "cd services/myservice"
write text "make build-docker"
write text "make run-docker"
end tell

理论上,这个块应该

1) 创建一个新标签
2)切换到新目录
3)构建一个docker镜像和
4) 运行那个 docker 镜像。

这偶尔会起作用,但更频繁的是我在第 4 步中遇到问题。具体来说,我将检查该选项卡以发现“make build-docker”是最后运行的命令。此命令需要一些时间,因此我假设在构建运行时发送了“make run-docker”并被忽略。有没有办法强制 applescript/iTerm2 等待此命令完成以便正确执行运行?

希望这很清楚。谢谢阅读!

最佳答案

如果您启用了 iTerm 的 shell 集成,您可以轮询 is at shell prompt确定命令是否已完成:

tell application "iTerm2"
tell current window
create tab with profile "BentoBox"
tell current session
write text "sleep 5"
repeat while not (is at shell prompt)
delay 0.5
end repeat
write text "sleep 5"
end tell
end tell
end tell

否则,您将希望将所有命令串连在一起:
write text "cd services/myservice; make build-docker; etc; etc; etc.."

或者将它们放在一个 shell 脚本中并执行:
write text "my_super_duper_shell_script.sh"

或者使用 AppleScript 将 cmds 写入 tmp 文件并执行:

回复: How can I create or replace a file using Applescript?

关于docker - 我可以强制applescript同步运行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46920048/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com