Applescript每5秒运行一次脚本

时间:2017-04-11 08:17:57

标签: applescript

我正在尝试将以下代码作为协程运行。有没有办法实现这个目标?

repeat delay 5 log theScript end repeat

1 个答案:

答案 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