Help with processes

Here is a piece of a script that I am currently using:

activate application "Mail"
tell application "System Events"
	tell process "Mail"
		keystroke "c" using {command down}
	end tell
end tell

This is fine if the program in which text is highlighted (selected) is Mail. I would like to make the script more useful. I need to be able to copy to the clipboard the text that is selected, despite the program in which it is selected (perhaps it is Safari, Mail, or Pages, etc)
From there the remainder of my script (no shown here) will paste the clipboard contents and manipulate it. (This part of the script is working ok.)

If no text is selected and the script is executed, I have used a try / on error / end try block to create an alert, however I would also like to know what script command to use to cause a script to terminate. Thanks

This should work:

tell application "System Events"
	set pN to name of (some process whose visible is true and frontmost is true)
	tell process pN to keystroke "c" using {command down}
end tell

Hope it works,
ief2

Following on from ief2

try this. save as an application

tell application "System Events"
	set pN to name of (some process whose visible is true and frontmost is true)
	set frontmost of pN to false
	tell process pN to keystroke "c" using {command down}
end tell

Could work.

Val

Also re quit

see http://macscripter.net/viewtopic.php?id=19226

Val