【问题标题】:How to wait until specific text is on screen before proceeding with script?如何在继续执行脚本之前等到屏幕上出现特定文本?
【发布时间】:2015-10-09 03:22:06
【问题描述】:

我是 applescript 的新手,所以任何帮助都将不胜感激!

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

谢谢!

【问题讨论】:

    标签: applescript


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      您可以在保持打开的 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/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-01-15
        • 1970-01-01
        • 2018-06-19
        • 2017-11-05
        • 2011-03-19
        • 1970-01-01
        • 2021-11-01
        • 1970-01-01
        相关资源
        最近更新 更多