【发布时间】:2026-01-19 12:40:01
【问题描述】:
我正在编写一个每 5 分钟显示一次的 applescript 应用程序。这将处于无限循环中。我的要求是,虽然它自启动以来一直运行 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() 实现,因为它没有多大价值。
【问题讨论】:
-
您所问的问题仅靠基本的 vanilla AppleScript 是不可能实现的。
-
我很好用 JS 连同它。我只想要功能。
标签: applescript applescript-numbers