Is "Quit others" possible?

If one holds down Option and Control whilst clicking an icon in the Dock, the resulting menu contains a Hide Others command, such that only the clicked application is visible on screen. This is helpful when making a presentation, recording a screencast, or in other circumstances. The one problem is that the programs running in the background can still generate errors, etc., that might awkwardly cause them to reappear during the screencast, presentation, etc.

Would it be possible to create some sort of command (or Service, or something) to "Quit Others" -- that is, a command that would quit all applications except the frontmost one?


Using the SO answer referenced by Diago, maybe something like the following modification can exclude the currently active application:

tell application "System Events"
    set the visible of every process to true
    set app_name to name of the first process whose frontmost is true
end tell
set white_list to {"Finder", app_name}
try
    tell application "Finder"
        set process_list to the name of every process whose visible is true
    end tell
    repeat with i from 1 to (number of items in process_list)
        set this_process to item i of the process_list
        if this_process is not in white_list then
            tell application this_process
                quit
            end tell
        end if
    end repeat
on error
    tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0
end try

Then you can add this as a service using Automator, and assign a keyboard shortcut for it in the Keyboard section of System Preferences.


There is an answer on SO about this Quit All Applications using Applescript? with code for an AppleScript that can quit all applications. I would guess it just needs to be modified to check what the active application is and then installed as a service on the Mac. There is an article about the latter available here.