Determine if App is active

I was having a problem, I couldn’t figure out how to determine if safari was active, and I searched and searched and couldn’t find an answer! After a while I found my answers, and I thought I’d post them here, in one single post so hopefully no other noobs will have to search around for long. I found that “if application process “Safari” is visible then” worked. I know it seems simple, but it took me (the super-noob) FOREVER to get! Anyway, if this is the wrong place to post this I would glady move this somewhere else.

this is the normal way, but you can also use the Finder as target application

tell application "System Events"
	if exists application process "Safari" then
		-- your code goes here
	end if
end tell