我正在尝试将以下代码作为协程运行。有没有办法实现这个目标?
repeat
delay 5
log theScript
end repeat
答案 0 :(得分:0)
使用on idle
处理程序并将脚本另存为应用程序
on idle
log theScript
return 5
end idle
如果是AppleScriptObjC应用程序,则无法使用idle
处理程序,另一种选择是Foundation框架的NSTimer
。
property timer : missing value
on applicationWillFinishLaunching:aNotification
set timer to current application's NSTimer's scheduledTimerWithTimeInterval:5.0 target:me selector:"timerFired:" userInfo:(missing value) repeats:true
end applicationWillFinishLaunching_
on timerFired:aTimer
log "timerFired"
end timerFired