我们可以使用以下代码在指定的时间内执行链接按钮的点击操作:
-- 设置触发时间
set triggerTime to "2021-08-01 12:00:00"
-- 定义要点击的按钮的名称
set buttonName to "链接按钮"
-- 定义在当前时间之前执行代码的函数
on runBeforeTriggerTime()
set currentDate to (current date)
set triggerDate to date triggerTime
return (currentDate < triggerDate)
end runBeforeTriggerTime
-- 开始轮询,直到触发时间
repeat until runBeforeTriggerTime() is false
delay 10 -- 等待 10 秒钟再检查时间
end repeat
-- 获取前台应用程序,并获取其中的窗口
tell application "System Events"
set frontApp to first application process whose frontmost is true
set frontWindow to first window of frontApp
end tell
-- 找到指定的按钮并单击它
tell application "System Events"
tell frontWindow
click button buttonName
end tell
end tell
在这里,我们设置触发时间和要点击的按钮的名称。然后,我们定义了 runBeforeTriggerTime()
函数,在当前时间和触发时间之间进行比较,直到触发时间到达为止。最后,您可以使用 System Events
应用程序对象找到指定的窗口和按钮,并模拟用户单击该按钮。
请注意,这种方法需要将脚本保存在磁盘上并在指定时间点手动运行,或者使用其他工具(如 cron)来自动化执行该脚本的操作。