Script gives errors for non-admin users

The following script:

on isRunning (AppName)
tell application “Finder”
set runningApps to (name of every process whose file type is “APPL”) as list
end tell
set numberOfApps to count of items of runningApps
repeat with thisName in reverse of runningApps
if thisName contains AppName then
return true
end if
end repeat
return false
end isRunning

returns an error “Scripting Component Error” whenever I tried to run as a non-admin user. If I allow the user to administer the computer (in Account settings) the script runs without error. Does the user have to have privileges to a particular folder to make queries about processes?

Thanks,

KF

A couple of observations…

First, under Mac OS X you should be targeting ‘System Events’ rather than the Finder for this information. Additionally, you automatically get a list back, so you don’t need to coerce it to a list.

Secondly, you can check if an item exists in a list without having to walk through the list by using AppleScript’s “contains” feature.

on isRunning(AppName)
	tell application "System Events"
		set runningApps to name of every application process
		if runningApps contains AppName then
			return true
		end if
	end tell
	return false
end isRunning

Thanks. I’ll try your suggestions.