Find App Path from Creator Code

Often you have scripts that include calls to applications that users have renamed. To avoid a request from the script to locate an application, use this handler to locate it within the script itself.

OS version:

set the_app to my path_from_cc("sfri")
if the_app is not equal to false then
	using terms from application "Safari"
		tell application the_app
		end tell
	end using terms from
end if

on path_from_cc(the_cc)
	if length of the_cc is not 4 then return false
	tell application "Finder"
		set the_process to (every process whose creator type is (the_cc as type class)) as list
		if the_process = {} then
			if exists application file id the_cc then
				return ((application file id the_cc) as alias) as string
				return false
			end if
			return ((file of item 1 of the_process) as alias) as string
		end if
	end tell
end path_from_cc