Need some Help here!!

This script works on OSX fine, but will not work on OS 9.2.2. The problem in OS9 is it will not go through the process it will put away disk right away. I need the disk to be put away after the application closes. Thank You and any help is appreciated .

AppleScript Begin—

tell application “Finder”
mount volume "afp://username:password@address/SCH
launch application “SCH”
end tell

property AppQuits : “SCH”

on idle {}
tell application “Finder”
set RunningApps to name of every process whose name is AppQuits –
if RunningApps = {} then –
tell application “Finder”
put away disk “SCH”
end tell
end if
end tell
return 30 –
end idle

When the script itself is launched, the stuff at the top is executed and then the action drops through immediately to the ‘idle’ handler. What’s happening here is that this first ‘idle’ happens while application “SCH” is still launching, before it’s registered as a process in the Finder.

You can either use some sort of ‘if’ block to stop the process check happening the first time round or, more simply, use an explicit ‘run’ handler (with its own return) after the ‘idle’ one.

In Mac OS 9 and earlier, if you try to get the name of a process that doesn’t exist, you’ll get an error. The best way to test for the existence of a process — both here and in OS X — is to use the Finder’s ‘exists’ command.

property AppQuits : "SCH"

on idle
  tell application "Finder"
    if not (process AppQuits exists) then --
      put away disk "SCH"
      my quitMe()
    end if
  end tell
  
  return 30 --
end idle

on run
  -- These commands don't belong to the Finder.
  mount volume "afp://username:password@address/SCH"
  tell application "SCH" to launch
  
  return 30
end run

on quitMe()
  quit -- quit this applet when finished
  error number -128 -- finish now
end quitMe

Thank you Nigel, you have been very helpful.

Best Regards,
Jeff