我可以强迫苹果同步运行吗?

我正在为iTerm2编写一个简单的applescript脚本,它会生成一堆标签,并开始在其中运行服务(我有很多微服务,并且都需要运行以在本地testing)。

事情大多是工作,但是我正在经历一些有点奇怪的行为,我认为这与苹果早期发送命令有关。 我们来看一个具体的例子:

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)创build一个新标签2)更改为一个新的目录3)build立一个docker图像和4)运行该docker图像。

这将偶尔工作,但更频繁地遇到步骤4的问题。具体来说,我将只检查标签以查明“make build-docker”是最后一个运行的命令。 这个命令需要一些时间,所以我假设“make run-docker”在构build运行时被发送并被忽略。 有没有办法强制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文件并执行:

回复 : 如何使用Applescript创build或replace文件?