Jump to content

Recommended Posts

Hello All

I am from those people who open so many windows apps and tabs, but at a certain point I feel overwhelmed and need for focus . So, I found this script and I modified the names of the apps that need to be persistent 

tell application "System Events" to set the visible of every process to true
set white_list to {"Finder","Todoist","Alfred 3","Snip","TextExpander","Alfred Preferences","ExpressVPN","Google Chrome"}

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
		if this_process is not in the frontmost then
			tell application this_process
            		quit
        		end tell
		end if	   
	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

However, the frontmost app still get closed. In addition, I want to minimize all apps in the white_list except if it is the frontmost, any ideas?

 

Thank you

Share this post


Link to post

telling an application can cause it to take focus, especially telling it to quit, as many apps show confirmation dialogs. So it's possible that the problem is the frontmost application changing while you're looping through the processes.

 

Try first making a list of the applications you want to quit, and the looping over that list to do the telling:

 

set quit_list to {}

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

        if this_process is not in the frontmost then

            set end of quit_list to this_process

        end if

    end if

end repeat

 

repeat with this_process in quit_list

    tell application this_process to quit

end repeat

Share this post


Link to post
14 minutes ago, deanishe said:

 if this_process is not in white_list then

        if this_process is not in the frontmost then

            set end of quit_list to this_process

        end if

  end if

 

Can be shortened to

 

    if this_process is not in white_list and this_process is not in the frontmost then

        set end of quit_list to this_process

    end if

Share this post


Link to post

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
×