Applescript 如何等待特定文本出现在屏幕上,然后再继续执行脚本?

Applescript 如何等待特定文本出现在屏幕上,然后再继续执行脚本?,applescript,Applescript,我是applescript的新手,因此任何帮助都将不胜感激 我试图让我的脚本只在特定文本出现在网页上时运行。我一直在为我的问题寻求帮助,但到目前为止都没有结果 谢谢 除非目标应用程序在其AppleScript字典中提供特定的事件处理程序,否则AppleScripts无法监视事件 解决方法是使用重复循环定期监视请求事件的状态,但这相当昂贵。您可以在保持打开的applescript应用程序中使用空闲处理程序。空闲处理程序允许代码以指定的时间间隔(秒)运行。 你可以从这个代码开始。另存为应用程序,并检

我是applescript的新手,因此任何帮助都将不胜感激

我试图让我的脚本只在特定文本出现在网页上时运行。我一直在为我的问题寻求帮助,但到目前为止都没有结果


谢谢

除非目标应用程序在其AppleScript字典中提供特定的事件处理程序,否则AppleScripts无法监视事件


解决方法是使用重复循环定期监视请求事件的状态,但这相当昂贵。

您可以在保持打开的applescript应用程序中使用空闲处理程序。空闲处理程序允许代码以指定的时间间隔(秒)运行。 你可以从这个代码开始。另存为应用程序,并检查它是否“在运行后保持打开状态”

另一种方法是使用OSX中的launchd实用程序在指定的时间或间隔运行脚本。这里有一个很好的教程:

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