Macos 使用计时器运行applescript

Macos 使用计时器运行applescript,macos,applescript,Macos,Applescript,我正在尝试运行applescript。脚本的内容并不重要,但我希望以一定的时间间隔运行它,直到满足特定的条件。例如,我想单击Safari浏览器中的菜单项(如果可用): 我要运行的applescript: on menuClick() tell application "System Events" tell process "Safari" click menu item "Simulator" of menu 1 of menu bar item "Develop" o

我正在尝试运行applescript。脚本的内容并不重要,但我希望以一定的时间间隔运行它,直到满足特定的条件。例如,我想单击Safari浏览器中的菜单项(如果可用):

我要运行的applescript:

on menuClick()
  tell application "System Events"
    tell process "Safari"
      click menu item "Simulator" of menu 1 of menu bar item "Develop" of menu bar 1
    end tell
  end tell
end menuClick
我希望脚本如何运行的伪代码(抱歉,我对applescript的了解有限):


伪代码在Applescript中的外观如何?

如果要定期运行Applescript,请使用“空闲”处理程序:

On idle
-- do this and this / add you code
return xxx
end idle
您运行代码,它将永远运行(除非代码包含quit命令)。返回后的xxx值是下次运行前的秒数(正!)。在您的代码中,您可以检查应用程序当前状态或任何其他内容。
如果不够,您可以使用launchd方法(se Apple launchd)。

这不起作用。但我玩了“尝试、出错、结束尝试”块,这似乎奏效了。除了当我试图在出现错误时再次调用
menuClick
时,我需要以某种方式避免堆栈溢出(不是此站点:P)
On idle
-- do this and this / add you code
return xxx
end idle