How do I Quit an application based on some other system process?

I am looking for a way to script the OS quitting an application, for instance Mail.app, when the screen saver activates. Is there a way to do that?

Model: MacBook Pro
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi,

save this as stay open application

on idle
	tell application "System Events"
		if process "ScreenSaverEngine" exists then
			quit application "Mail"
			quit me
		end if
	end tell
	return 5
end idle