2017-04-11 63 views
-1

我希望能够每隔5秒运行一次applescript而不停止其他脚本的运行。我不能使用每5秒Applescript运行脚本

repeat delay 5 log theScript end repeat

,因为它会做到这一点,而不是在做任何事。有什么建议么?

回答

0

使用on idle处理程序和脚本保存为应用

on idle 
    log theScript 
    return 5 
end idle 

在您无法使用idle处理器的AppleScriptObjC应用程序的情况下,另一种是基础架构的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 
+0

我试着把这个直接放在我的应用程序中,但它不工作。 '在空闲时 显示通知“工作” 返回5 结束空闲' –

+0

它应该在保存为应用程序的任何脚本中工作。 – vadian

+0

我只是把它放到我的应用程序委托脚本在Xcode并运行它。 –