Not sure how to check for a running application in Mac OS 9

I know that my topic doesn’t really fit in this section but, I wasn’t sure where else to ask this. Ok, a liitle backstory: I’ve got the game Mighty Mike (a.k.a Power Pete) set up to launch when my installation of Mac OS 9.0.4 launches in SheepShaver. I then want a script (also in the start up items folder) to check if Mighty Mike is running & if it isn’t, it then tells Finder to shut down. Here’s what I have so far:


tell application "Finder"
	if exists (some process whose name contains "Mighty Mikeâ„¢") then
		beep
	else
		tell application "Finder"
			shut down
		end tell
	end if
end tell

If I launch the script in the AppleScript editor & run it & then quit the editor, SheepShaver shuts down/quits as expected. But, if the script is in the Start Up Items folder & I quit Mighty Mike, the Script Editor just adds on blank lines to the beginning of the script. Any help would be greatly appreciated.

It’s too bad that this site shut down the old Mac OS forum, because some of us are still scripting for System 7 or OS 8/9 and running the scripts in BasiliskII or SheepShaver. Anyway, if it’s OK to post in this forum, you actually don’t need two items in your Startup Items in OS 9.0.4. One script should be enough.

What I think you’re trying to do is this: run Mighty Mike when SheepShaver starts, and shut down SheepShaver when you quit Mighty Mike. I don’t really know anything about AppleScript, so the following script is probably a horrible illogical kludge, but it seems to work on a setup in which I run WordPerfect for the Mac in precisely the same way you want to run Mighty Mike.

You need to save it from the Script Editor in the “classic applet” format with the “Stay Open” option checked.

Let us know if it works on your setup:

property appRunning : 0

on run
	tell application "WordPerfect" to launch
	repeat while appRunning is 0
		tell application "Finder"
			if exists (some process whose name contains "WordPerfect") then
				set appRunning to 1
			end if
		end tell
		delay 1
	end repeat
end run

on idle
	tell application "Finder"
		if exists (some process whose name contains "WordPerfect") then
		else
			set appRunning to 0
		end if
	end tell
	if appRunning is 0 then
		tell application "Finder" to shut down
	end if
	return 2  -- pauses two seconds before trying again; can change to 1 if you're impatient
end idle

What’s missing in this is some code that that brings your game to the foreground at the start of the “on idle” block. What I do to achieve this is this: I set a “firstRun” variable to true at the end of the “on run” block, then test for that variable at the start of the “on idle” block; if it’s true, then I tell WordPerfect to activate and I set the variable to false (so it stays false, and is false each time the “on idle” block repeats). This test immediately follows the “on idle” line. By doing this I prevent the script from activating WordPerfect every two seconds while I’m trying to use some other application. All this may not be necessary in your setup if the game comes to the foreground immediately.

Thank you!! It seems to work but, there seems to be some shutdown errors. I also have a couple of questions. How do I save the script?

If I save it as a compiled script, Script Editor just opens on Startup.

if I save it as a classic applet, I get this message after startup:

There also seems to be some options for saving it as a classic applet:

After I quit Mighty Mike (after launching it with any of the saved versions), I’m returned to Finder & I get this cursor icon: (kinda like the spinning beach ball of doom). I then have to force quit SheepShaver. I then get the normal shut down error message:

Or, do I save it as run-only? Again, there are many options:

Again, there are the same options for saving it as a classic applet

If I place a run-only script in the start-up items folder, I get this message:

The only option that seems to almost work is saving it as a Mac OS X applet

I still get this message when I run it:

Even though when I quit Mighty Mike, and SheepShaver is shut down, I still get the shut down error message

I’ve tried changing the last part of the code to:


on idle
   tell application "Finder"
       if exists (some process whose name contains "WordPerfect") then
       else
           set appRunning to 0
       end if
   end tell
   if appRunning is 0 then
       delay 100
       tell application "Finder" to shut down
   end if
   return 2 -- pauses two seconds before trying again; can change to 1 if you're impatient
end idle

but, I still get the shut down error message. Thank you for your help though. I feel like the script might just need a small change but, I can’t figure it out.

I was adding the “how to save” instructions while you were posting your message.

From the Script Editor, save it as a “classic applet.” Make sure to have the “Stay Open” box checked. Also have the “Never Show Startup Screen” box checked.

When you use those options, use my ORIGINAL script. Do NOT make any changes in the original script that I posted until after you have tested it.

Of course, test it simply by launching it from the desktop before you put it in the Startup Items folder.

You can find a copy of the script in this ZIP file (this version includes my “bring to the foreground” code).

http://dl.dropbox.com/u/271144/AutoShutScript.zip

The “bring to the foreground” code may or may not prevent the “in progress” black-and-white cursor disk from appearing. I need to click in the application to get it to start; you may need to also.

Hrm, at least I don’t get that message when I run the scripts. But, when I quit Mighty Mike, I get thrown back to the Finder & then I get that spinning icon. I tried saving it a classic applet & as a Mac OS X applet. Got the same results with every try. I then had to force quit SheepShaver each time. Thank you for your help. I really do appreciate it.

Well, I don’t know what else to suggest, except possibly this:

  1. Try it with the script that I linked to, in case you mistyped something. You’ll need to edit it to replace “WordPerfect” with your game.

It that doesn’t work, then try it again, but this time:

  1. Start up SheepShaver with the shift key held down so that you turn off any extensions. Launch the script manually (it won’t start from the Startup Items folder if you held down the shift key), and see what happens. If it works correctly, then you can disable extensions until it finally works.

Of course, your game might launch other processes that get in the way of a shutdown. You may need to explore that possibility.

I’m going to upload my project to my dropbox account in a little while. That way, you can what I’m working with. Thanks again for your help. I’ll have it uploaded in about 30 minutes