Mac OS 9 Lives

Classic Mac OS Software => System Utilities & File Management => Topic started by: Canal Noises on July 04, 2017, 10:46:25 AM

Title: Detect Application Close with AppleScript
Post by: Canal Noises on July 04, 2017, 10:46:25 AM
I have a couple dozen old games that I'm working on getting set up in OS 9, and I've been using AppleScript to simplify the process of launching them. Many of the games require the CD to be mounted, so I have my script mount a disk image, set the screen resolution and color depth if needed, and then launch the game.

That's all pretty simple to script, but when the application is closed I'd like to have the screen resolution and color depth set back to normal and have the disk image unmounted—basically have the script clean up after itself. I've come across a few ways to accomplish that on OS X, but nothing on the classic systems. Does anyone know if it's possible to do what I'm wanting to do?
Title: Re: Detect Application Close with AppleScript
Post by: IIO on July 04, 2017, 12:41:06 PM
"unmount volume" on MacOS9 is equal to "move to trash". i think if you want to track the name of the opened image for later unmounting you would have to leave the applescript runtime open while you run the game...?
Title: Re: Detect Application Close with AppleScript
Post by: Canal Noises on July 04, 2017, 01:52:20 PM
I've actually got the disk ejecting code down, I think. If the name of the disk is known it's simple to unmount/eject it:
Code: [Select]
tell application "Finder" to eject disk "Disk Name"
What I'm stuck on is how to have that statement triggered when the game quits. What I'm thinking is that if I leave the script running I can have it periodically check to see if the game is still running, and then only move on to eject the disk when it no longer sees that process.

I think I may have actually found some commands that I can use to make this work. I'm going to try it out and I'll report back. Thanks for the reply, IIO :)
Title: Re: Detect Application Close with AppleScript
Post by: Canal Noises on July 04, 2017, 02:56:40 PM
Got it! Here's my script, in case it can help anyone else do the same thing.

Summary of what it does:
Code: [Select]
set monitorSettings to screen list starting with main screen --Store current display settings

tell application "Finder"
open file "Macintosh HD:Applications (Mac OS 9):Disk Image.iso" --Mount the CD image
set screens to {screen size:{640, 480}, color depth:8} --Set the display resolution and color depth (640x480 at 256 colors)
open file "Mounted Disk Image:App Name" --Launch app
end tell

--Watch for app to quit
set appRunning to "1"
repeat until appRunning is "0"
tell application "Finder"
if exists process "App Name" then
set appRunning to "1"
else
set appRunning to "0"
end if
end tell
end repeat

set screens to monitorSettings --Revert to original display settings

--Eject the CD image:
tell application "Finder"
eject disk "Mounted Disk Image"
end tell
Title: Re: Detect Application Close with AppleScript
Post by: IIO on July 05, 2017, 02:04:44 AM
>>periodically check to see if the game is still running

yeah, classic workaround for stuff like that. thanks for sharing your results.