Jump to content

Force Quit All Apps Except App with Focused Window


Recommended Posts

Sometimes I have so many apps running and want to simplify without restart.  I'd like to keep the focused app open if possible, most times this is Chrome.

 

I searched extensively online and found the below applescript.  I have been trying to tweak it but am unable to reach success.  I appreciate the support of this community and would be very thankful for any help.

 

 

tell application "System Events" to set the visible of every process to true
set white_list to {"Finder"}

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
 
Edited by jloveblaze
Link to comment

Oh this is a quick action like `command+option+ESC`. :)

 

I appreciate your quick response but I know how to bring up the option command menu an pick the apps.  I am looking for a way to use alfred to close all apps without having to manually go to that menu and force quit each app. The script I posted above I think sheds some light on how to work it.  Im just not sure how to make an Alfred Workflow out of it.

 

Thanks!

Link to comment

@Hzlzh That worked Excellently!  It forced quit all apps. Thank you so much for packaging it an hosting it.  I saw you included the language: /osascript  which is something I wasn't doing.

 

 

Which modifier can I add to the code to make an exception for specific a specific app?  (so all apps but a specific one close)

 

I tried to make it so that all apps closed except for Chrome by replacing all instances of the words "Finder" with the words "Chrome" but Finder still stayed open and Chrome closed...

 

Will look into this more. Thanks again for going over and beyond to help! 

Edited by jloveblaze
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...