applescript 循环任务

比如每过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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容