Search code examples
macosapplescriptvoiceover

Applescript to "quit current application" dialog


I am trying to make an Applescript to run with VoiceOver to popup a dialog asking to quit the current application. I was able to get one to work but it only works some of the time.I believe this is because of memory issues in some applications, that is why there is a delay. I tried telling the "frontmost" application to quit and it didn't work either.

    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

Solution

  • See if the following works any better. No need for UI stuff, as the vast majority of apps will understand, or respond to the quit command. The first thing I do is get the frontmost process (the file path, actually, which is safer for some apps -- like NeoOffice, for example -- that is, safer than just getting the 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