Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

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.

share|improve this answer
    
+1 For modifying the script –  Diago Mar 16 '12 at 15:45
    
@Matt Swain, did you just put together this post, or is there an error somewhere in the system? Because I was just trying to answer my own question, following Diago's lead, and when I clicked submit, this answer appeared, but attributed to you. But either we wrote the same thing, which is entirely possible, I suppose, or somehow my post got attributed to someone else. –  Daniel Lawson Mar 16 '12 at 15:50
    
@DanielL Yeah I wrote this post - can't see your post, but if like you say it was very similar to this, then maybe it was automatically filtered? Weird. –  Matt Swain Mar 16 '12 at 16:24
    
OK, wow, you used a different variable name than I did. What you called appname I called current_process. We just had the same idea. Well, well done. –  Daniel Lawson Mar 16 '12 at 16:29
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.