2015-10-08 20 views

回答

0

AppleScripts無法監視事件,除非目標應用程序在其AppleScript字典中提供了特定的事件處理程序。

解決方法是使用重複循環來定期監視所請求事件的狀態,但這非常昂貴。

0

您可以在住宿開AppleScript的應用程序中使用空閒處理器。空閒處理程序讓代碼以指定的時間間隔以秒爲單位運行。 您可以從此代碼開始。保存爲應用程序,並檢查它是否「運行後保持打開」。

property browserName : "Safari" 
property searchString : "google" 
property theDelay : 60 -- delay time in seconds 

on run 
    -- do any setup here 
end run 

on idle 
    -- do your stuff here 
    tell application "System Events" to set appRunning to ((name of processes) contains browserName) 
    if appRunning then 
     tell application "Safari" to set t to the text of document 1 
    end if 
    if t contains searchString then 
     -- do stuff 
     beep 

    end if 
    return theDelay 
end idle 

on quit 
    -- do any cleanup necessary upon quit 
    continue quit 
end quit 

另一種方法是使用OS X中的launchd實用程序在指定的時間或間隔運行腳本。這裏有一個很好的教程吧:http://nathangrigg.net/2012/07/schedule-jobs-using-launchd/

相關問題