我是一個相對較新的applescript,所以任何幫助都將非常感謝!如何在繼續使用腳本之前等待特定文本出現在屏幕上?
我想讓我的腳本只在特定文本出現在網頁上時才運行。我一直在努力爲我的查詢尋求幫助,並且到目前爲止已經幹了。
謝謝!
我是一個相對較新的applescript,所以任何幫助都將非常感謝!如何在繼續使用腳本之前等待特定文本出現在屏幕上?
我想讓我的腳本只在特定文本出現在網頁上時才運行。我一直在努力爲我的查詢尋求幫助,並且到目前爲止已經幹了。
謝謝!
AppleScripts無法監視事件,除非目標應用程序在其AppleScript字典中提供了特定的事件處理程序。
解決方法是使用重複循環來定期監視所請求事件的狀態,但這非常昂貴。
您可以在住宿開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/