Quit all appplications

Hello,

In my ASOC application, I quit all the applications in this way:

            tell application "System Events" to set theapps to name of every application process whose visible is true and name is not "Finder"
            set keepapp to {"MyApp"}
            repeat with closeapp in theapps
                if closeapp is not in keepapp then quit application closeapp
            end repeat

Is it possible to get the same result without use System Events?

Thanks!

Yes, there is a native ASOC way with NSWorkspace and NSRunningApplication.

NSApplicationActivationPolicyRegular filters the regular GUI apps.


set runningApplications to current application's NSWorkspace's sharedWorkspace()'s runningApplications()
set keepApps to {"Finder", "MyApp"}
set regularActivationPolicy to current application's NSApplicationActivationPolicyRegular
repeat with anApplication in runningApplications
	set appName to anApplication's localizedName() as text
	if anApplication's activationPolicy() is regularActivationPolicy and appName is not in keepApps then
		anApplication's terminate()
	end if
end repeat

Thank you very very much StefanK!

It’s simply perfect. :wink: