我正在编写一个applescript 应用程序,它每5 分钟说一次。这将处于无限循环中。我的要求是,虽然它自启动以来一直运行 24x7,但下次当我单击应用程序图标时,它应该显示对话框以通过 3 个按钮之一获取用户输入。
我有 3 个按钮。
- 暂停通知
- 通知开启
- 通知关闭
当代码处于无限循环时,我单击应用程序图标,对话框提示不会出现以通过上述 3 个按钮获取用户输入。如何解决?
global isSoundEnabled, isNotifEnabled
on run
set isSoundEnabled to true
set isNotifEnabled to true
set theDialogText to "The curent date and time is " & (current date) & "."
display dialog theDialogText buttons {"Pause", "Notif ON", "Notif OFF"} default button "Notif ON" cancel button "Pause" with icon caution
if result = {button returned:"Notif ON"} then
set isSoundEnabled to true
set isNotifEnabled to true
loop()
else if result = {button returned:"Notif OFF"} then
set isSoundEnabled to false
set isNotifEnabled to false
end if
end run
on loop()
repeat while true
set min to getMin()
get min as integer
#if (min mod 5) = 0 then
if (min / 5) > 1 then
set timee to getTimeInHoursAndMinutes()
if isNotifEnabled then
display notification timee
end if
if isSoundEnabled then
say timee
end if
#delay 60
#if isSoundEnabled is not
end if
#exit repeat
end repeat
end loop
我没有故意添加 getTimeInHoursAndMinutes() 和 getMin() 实现,因为它没有多大价值。