My new script to quit all hidden apps is not working

Hello,

I am a newbie to AppleScript (only messed around with the Record feature on System 7 before), and this is my first post on this forum!

I just made a script, copying some code from a forum ( http://forums.macrumors.com/showthread.php?t=275858 ) and putting in some of my own (barely any). It freezes Script Editor when I run it and I have to hide and show Script Editor and wait for it to finish. It does not show the error dialog that I have put in the code.

Here is the script:

set white_list to {"Finder", "iTunes"}

try
	tell application "Finder"
		set process_list to the name of every process whose visible is false
	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
	display dialog "There was an error quitting the application" + this_process + "." buttons {"Quit"} default button 1
	error number -1
end try

AppleScript: AppleScript 20.1; Script Editor v2.2.1 (100.1)
Browser: Safari 525.20) OmniWeb/v622.6.0.109966
Operating System: Mac OS X (10.5)

Hi,

the application, which knows everything about processes, is System Events.
Some information are available also in Finder, but using System Events is preferable.

If you check only the visible property, you get all background only processes, too (like loginwindow, Dock etc.).
I guess, it’s not intended (and in some cases not possible) to quit those applications.

try this


set white_list to {"Finder", "iTunes"}

try
	tell application "System Events"
		set process_list to the name of every process whose background only is false and visible is false
	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
	display dialog "There was an error quitting the application" + this_process + "." buttons {"Quit"} default button 1
	error number -128
end try