我有以下脚本,它使用 Mac 日历在屏幕上显示每日消息。问题是几分钟左右后就会超时。我希望它在屏幕上保留至少 6 小时,或者直到我使用“确定”按钮将其关闭。请帮助修复缺失的代码,以便更长时间地显示消息。
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
我尝试了以下方法:
display dialog dailyMessage buttons {"OK"} default button "OK"
delay (6 * hours)
但它所做的只是使应用程序在任务栏上保持打开状态,而不是消息。
我设法通过添加以下代码使其正常工作:
displayNotification(dailyMessage, 6 * hours)
on displayNotification(theMessage, duration)
display dialog theMessage buttons {"Close"} default button "Close" with title "Daily Message" giving up after duration
end displayNotification