Applescript“退出当前应用程序”对话框

时间:2014-09-09 04:58:20

标签: macos applescript voiceover

我正在尝试使用VoiceOver运行Applescript以弹出一个要求退出当前应用程序的对话框。我能够让一个工作,但它只在某些时候工作。我相信这是因为某些应用程序中的内存问题,这就是为什么会出现延迟。我试着告诉最前面的"申请退出,它也没有。

    display dialog "Quit current application?" buttons {"cancel", "ok"} default button         "ok"
    if result = {button returned:"ok"} then
        delay 1.7

        tell application "System Events" to key code 12 using command down

    else if result = {button returned:"cancel"} then

    end if

1 个答案:

答案 0 :(得分:0)

查看以下内容是否更好。不需要UI内容,因为绝大多数应用程序都会理解或响应quit命令。我做的第一件事就是获得最前面的进程(file路径,实际上,这对于某些应用程序更安全 - 例如NeoOffice - 也就是说,比获取name更安全

tell application "Finder" to set p to item 1 of (get file of (processes whose frontmost = true)) as text

display dialog ("Quit current application?" & return & "(" & p & ")") buttons {"cancel", "ok"} default button 2

if button returned of (result) = "ok" then
    tell application p to quit
end if