Checking Application, Logging off and quiting the script!

Hi all,

I work in a school and we use macs and windows with citrix. The kids use apple laptops and i need a script to:

  1. Launch the connection file to start the application (Easy, managed this!)
  2. Check to see if the citrix client is running every 6 seconds (Managed this one too!)
  3. If the client is no longer running log off (sort of managed this one?)

The problem that i have and the solution that i need are as follows:
a. I would be nice if it logs them off straight away, rather than asking to from the promt
b. Once the script is saved as an application i need the script to exit at log off.

any ideas or hints will be greatly appreciated, the script so far is as follows:

tell application "Finder" to set myFile to file "connect" as alias
tell application "Citrix Client"
	launch
	open myFile
end tell

repeat
	delay 6
	tell application "System Events"
		if exists process "Citrix ICA Client" then
		else
			tell application "System Events"
				keystroke return
				log out
			end tell
		end if
	end tell
end repeat