2017-04-11 64 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並運行它。 –