Mac Script Editor自定义日历消息超时延长问题
Mac AppleScript 实现对话框持久显示(6小时或手动关闭)
问题根源:你之前把
delay放在display dialog之后,此时对话框已经在你点击OK后关闭,delay只是让脚本暂停运行,根本无法延长对话框的显示时间。加上Calendar触发的脚本可能会触发系统超时机制,导致对话框自动消失。解决方案:利用
display dialog的giving up after参数设置自动关闭时长,同时用with timeout块避免脚本被系统提前终止。
修改后的完整脚本:
set messageList to {"Daily message 1", "Daily message 2", "Daily message 3", "etc..."} set currentDate to (current date) set startOfYear to date ("January 1, " & (year of currentDate) as string) set dayOfYear to (currentDate - startOfYear) div days + 1 set messageIndex to (dayOfYear mod (count of messageList)) + 1 set dailyMessage to item messageIndex of messageList -- 让对话框持续显示6小时,或直到点击OK按钮 with timeout of (6 * hours) seconds display dialog dailyMessage ¬ buttons {"OK"} default button "OK" ¬ giving up after (6 * 3600) -- 6小时转换为秒数 end timeout
- 代码说明:
giving up after (6 * 3600):直接指定对话框在6小时后自动关闭,若你提前点击OK则立即关闭。with timeout of (6 * hours) seconds:延长脚本的超时时间,避免系统因脚本长时间等待用户输入而强制终止它。
内容的提问来源于stack exchange,提问作者Reubz
相关产品推荐
相关产品推荐

