
我不確定蘋果腳本是否是我需要的,但它似乎可以滿足我需要的大部分功能。請隨意提供替代方案。
我需要在準確的時間向程式發送角色以開始倒數影片。我的蘋果腳本是
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
第一行。