Docker 我可以强制applescript同步运行吗?
我正在为iTerm2编写一个简单的applescript脚本,它生成一组选项卡并在其中运行服务(我有很多微服务,所有这些都需要在本地运行来测试) 事情基本正常,但我遇到了一些稍微奇怪的行为,我认为这与applescript提前发送命令有关。让我们看一个具体的例子:Docker 我可以强制applescript同步运行吗?,docker,scripting,applescript,iterm2,Docker,Scripting,Applescript,Iterm2,我正在为iTerm2编写一个简单的applescript脚本,它生成一组选项卡并在其中运行服务(我有很多微服务,所有这些都需要在本地运行来测试) 事情基本正常,但我遇到了一些稍微奇怪的行为,我认为这与applescript提前发送命令有关。让我们看一个具体的例子: create tab with default profile tell the current session write text "cd services/myservice" write text "make b
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”是最后一次运行的命令。这个命令需要一些时间,所以我假设“makerundocker”是在构建运行时发送的,并且被忽略。有没有办法强制applescript/iTerm2等待此命令完成,以便正确执行run
希望这是清楚的。谢谢你的阅读 如果已启用iTerm的shell集成,则可以在shell提示符处轮询
以确定命令是否已完成:
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
否则,您将希望将所有命令串在一个tell中:
write text "cd services/myservice; make build-docker; etc; etc; etc.."
或者将它们放在shell脚本中并执行以下操作:
write text "my_super_duper_shell_script.sh"
或者使用AppleScript将CMD写入tmp文件并执行以下操作:
write text "my_super_duper_shell_script.sh"
re:还要注意,bash默认会忽略错误,除非您明确告诉它不要这样做。使用write text“cd services/myservice&&make build docker&&etc&&etc&&etc&&etc…”确保每个shell命令仅在上一个命令成功时执行。或者,如果要保存为.sh
文件,请在顶部添加set-e
命令,以便在任何命令失败时通知bash中止脚本。