Applescript 如何确定应用程序退出事件

Applescript 如何确定应用程序退出事件,applescript,Applescript,我使用applescript通过脚本编辑器创建了一个应用程序。在代码中,我使用“repeat…end repeat”来模拟计时器。编译代码时,我运行了应用程序。它工作得很好,但是,如果我右键单击应用程序图标,选择菜单“退出”,什么也不会发生。 我知道我应该做一个“退出”检查,但是,我不知道怎么做。 有人能帮忙吗 on main() set f1 to "/System/Library/Sounds/Pop.aiff" set f2 to "/System/Library/Sou

我使用applescript通过脚本编辑器创建了一个应用程序。在代码中,我使用“repeat…end repeat”来模拟计时器。编译代码时,我运行了应用程序。它工作得很好,但是,如果我右键单击应用程序图标,选择菜单“退出”,什么也不会发生。 我知道我应该做一个“退出”检查,但是,我不知道怎么做。 有人能帮忙吗

on main()

    set f1 to "/System/Library/Sounds/Pop.aiff"
    set f2 to "/System/Library/Sounds/Ping.aiff"
    set f3 to "/System/Library/Sounds/Glass.aiff"
    set f4 to "/System/Library/Sounds/Tink.aiff"

    repeat
        set now to current date
        set h to hours of now
        set m to minutes of now
        set s to seconds of now

        if (h = 6) and (m = 30) and (s = 0) then 
                --some code here
        end if

        delay 0.5

    end repeat

end main

重复循环会阻塞代码

当代码保存为应用程序时,请使用on idle处理程序,该处理程序根据返回值定期调用

global f1, f2, f3, f4

on run
    set f1 to "/System/Library/Sounds/Pop.aiff"
    set f2 to "/System/Library/Sounds/Ping.aiff"
    set f3 to "/System/Library/Sounds/Glass.aiff"
    set f4 to "/System/Library/Sounds/Tink.aiff"
end run

on idle   
    set {hours:h, minutes:m, seconds:s} to current date
    if (h = 6) and (m = 30) and (s = 0) then 
            --some code here
    end if
    return 1
end idle