在特定秒数运行 applescript

在特定秒数运行 applescript

我不确定 Apple 脚本是否是我需要的,但它似乎可以满足我的大部分需求。请随意提供替代方案。

我需要在准确的时间将一个字符发送到程序以启动倒计时视频。我拥有的 Apple 脚本是

tell application "ProPresenter 5"
    activate
end tell
tell application "System Events"
    keystroke "z"
end tell

我需要的是能够在一天的 10:40:25 开始,然后在第二天的 10:40:15 开始。我看到的所有指南都涉及日历或自动程序,但它们的分辨率为 1 分钟。我也只需要提前约 20 分钟进行设置

如果重要的话我在 os x 10.8.5

答案1

这是我为您设置的一个小功能,它将显示一个对话框,要求您输入时间,以便系统事件发送击键。您可以将此脚本保存为应用程序,并在需要时运行它。另一个选项是删除代码的前两行并将其替换为以下内容…… property requested_time : "10:40:25 AM”。然后,您可以将脚本添加到 iCal 事件中,以便每天在您选择的任何时间启动

set requested_time to display dialog "Please Enter Your Start Time With The Following Format: Hour:Minutes:Seconds" default answer "10:40:25 AM" buttons {"OK"} default button 1
set requested_time to text returned of requested_time
set theTime to time string of (current date)

tell application "ProPresenter 5" to launch -- Opens The App Without Bringing It Up Upfront. Added This Line To Make Sure Your Application Is Running When System Events Sends The Keystroke.  You Can Always Remove This Line If You Prefer

repeat until theTime is greater than or equal to requested_time -- Added The "Greater Than" Just As A Failsafe
    delay 1
    set theTime to time string of (current date)
end repeat

tell application "ProPresenter 5" to activate
delay .5 -- My system did not need this delay.  Yours may not either, but I added it just in case.  
tell application "System Events"
    keystroke "z"
end tell

或者您可以将此版本的脚本保存为应用程序。

property requested_time : "10:40:25 AM”
set theTime to time string of (current date)

tell application "ProPresenter 5" to launch -- Opens The App Without Bringing It Up Upfront. Added This Line To Make Sure Your Application Is Running When System Events Sends The Keystroke.  You Can Always Remove This Line If You Prefer

repeat until theTime is greater than or equal to requested_time -- Added The "Greater Than" Just As A Failsafe
    delay 1
    set theTime to time string of (current date)
end repeat

tell application "ProPresenter 5" to activate
delay .5 -- My system did not need this delay.  Yours may not either, but I added it just in case.  
tell application "System Events"
    keystroke "z"
end tell

然后,您可以创建一个新的日历事件以每天重复,并在 20 分钟前启动您保存为应用程序的脚本

在此处输入图片描述

答案2

您可以简单地使用 AppleScriptdelay命令来延迟脚本在精确的分钟内执行,无论多少秒。

按照您的例子:如果您希望它在 10:40:25 运行...将您的脚本设置为在 10:40:00 执行,但将命令放在delay 25第一行。

相关内容