比如每过10分钟提醒该休息啦
repeat
display dialog "Time to rest"
delay 600
end repeat
delay 600表示暂停10min,也就是每隔10min种提醒一次!
循环显示指定内容
set theMessages to {"Hello there!", "How are you?", "Let's learn about AppleScript!"}
repeat with n from 1 to 3
display dialog (item n of theMessages)
end repeat
一个小游戏,自己读吧
set answer to random number from 1 to 5
set guess to 0
repeat while guess is not equal to answer
set guess to text returned of (display dialog "Guess again! Choose a number from 1 to 5" default answer "1") as number
end repeat
display dialog "That's right! " & answer & " is the answer!"
上面的另一种写法
set answer to random number from 1 to 5
set guess to 0
repeat until (guess = answer)
set guess to text returned of (display dialog "Guess again! Choose a number from 1 to 5" default answer "1") as number
end repeat
display dialog "That's right! " & answer & " is the answer!"
参考
http://www.tuicool.com/articles/R7rmMfm
https://computers.tutsplus.com/tutorials/save-time-and-effort-with-applescript-repeat-loops--mac-45805