Script to keep demo game running

I have been asked to setup an educational game as part of an exhibit at a local Children’s Museum. The game is a commercial program and I have no means on altering the code. I need to have the program launch at startup (which is easy enough to do), but I have to prevent the children from exiting the program or, if they do exit, I need to immediately re-launch the app before the children can do anything else. My past experience shows that a 6 year old can break just about anything if given just a split second and a mouse click. The computer is an iMac using OS 10.2 and a touch screen monitor. The touch screen will be the only interface the children will have access to.

I have tried writing an AppleScript (my first) that looks like the following:

repeat until false
tell application “My Educational Game”
activate
end tell
end repeat

The program launches the first time, but after the user exits, I get an AppleScript error of “Connection is invalid”. I have not been able to find any help on this error. Any ideas on what the best way to handle this is? There are many creative ideas coming from this group, but I havn’t seen anything here that addresses a situation similar to this. I would also like to be able to completely hide the Finder program so the kiddies can’t mess with the system while it is waiting for the program to launch. I have hid everything on the desktop and managed to get the Dock out of the way, but can’t seem to get rid of Finder. Any ideas would be greatly appreciated.

Save the following script as a stay open application (adjusting the path to the application and the application name properties, of course):

property path_to_app : "path:to:My Educational Game"
property app_name : "My Educational Game"

on idle
	tell application "System Events" to set open_apps to name of processes
	if app_name is not in open_apps then tell application path_to_app to activate
	return 2 --seconds
end idle

Then, use Drop Script Backgrounder to make the new script application a faceless background script. Finally, add the script application to the login items. That should do it.

Jon

You may also want to use something like Menu Master to disable the “Quit” menu item for the game.

Jon

Thanks so much, Jon, for the suggestions. I have used your script, but I still get the error “Connection is invalid” after the game is exited. Although now the game does relaunch once I click on “OK”, but the “Connection is invalid” error comes up between each run of the program. What does it mean by “Connection is invalid”?

When I drop the script into Drop Script Backgrounder nothing comes back after the game is first exited. I assume the error is coming up, but is in the background and invisible to me. Any further suggestions?

Adding a try block to trap the “Connection is Invalid” error should sufficiently silence it:

property path_to_app : "path:to:My Educational Game"
property app_name : "My Educational Game"

on idle
	tell application "System Events" to set open_apps to name of processes
	try
		if app_name is not in open_apps then tell application path_to_app to activate
	end try
	return 2 --seconds
end idle

Jon

That did it! You are a gentleman and a scholar.

Thanks again,
Mark