Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: Looking for a way to automatically unmount CD images after a game quits  (Read 1478 times)

n8blz

  • 16 MB
  • ***
  • Posts: 22
  • New Member

Good evening gentlemen

My kids and I do a lot of retrogaming on my old Macs. One of the constant annoyances of doing so on OS9 is the CD images and the way they accumulate and clutter up the desktop unless you eject them all. It’s such a simple, automate-able process: mount this image, open this application, when this application quits unmount this disk.

I have come across pre compiled Applescripts for OSX games that do this, but never the script source. The new and excellent software Gamebox also does this for you, so it’s clearly possible. I am wondering if anyone has an Applescript source or other helper application that can do this? I intend to share the results of this thread, if there are any, on the ‘Garden with clear instructions on how to set it up for a given game.

Thank you for your suggestions!
Logged

n8blz

  • 16 MB
  • ***
  • Posts: 22
  • New Member

Credit to MikeTomTom at the ‘Garden for writing most of the script.

Here is the applescript:

>property idlePeriod : 0.5
>
>tell application “Finder”
>   activate
>   open file “ISO-FILENAME” of folder “ISO-LOCATION-PATH” of disk “ISO-LOCATION-DISK”
>   delay 2
>   open file “GAME-FILENAME” of folder “GAME-LOCATION-PATH” of disk “GAME-LOCATION-DISK”
>end tell
>
>on idle
>   tell application “Finder”
>      set x to every process
>      set y to application “GAME-FILENAME”
>      if y is in x then
>         return idlePeriod
>      else
>         delay 5
>         put away disk “ISO-DISC-NAME”
>         quit me
>      end if
>   end tell
>end idle
>
>on quit
>   continue quit
>end quit

The below might be obvious to applescripters but I am describing it in great detail for posterity.

Where it says “ISO-FILENAME” you would write out the name of the disk image file as it appears in the Finder.

Where it says “ISO-LOCATION-PATH” you would write out the path to your image. For example, if your image is named “CD Image.iso” and is located in your Applications folder, then this whole line would read:

   open file “CD Image.iso” of folder “Applications” of startup disk

Where it says “ISO-LOCATION-DISK” you can put the name of the disk on which the ISO resides, or if it’s on your startup disk you can just put “of startup disk.”

Where it says “GAME-FILENAME” that is the name of the executable application file as it appears in the Finder.

Where it says “GAME-LOCATION-PATH” you would write out the path to your game. For example, if your game is named “Warcraft II” and is located in your Applications folder, then this whole line would read:

   open file “Warcraft II” of folder “Applications” of startup disk

Where it says “GAME-LOCATION-DISK” you can put the name of the disk on which the game resides, or if it’s on your startup disk you can just put “of startup disk.”

After writing out the script, you click on “check syntax” and it should ask you where is the application “GAME-FILENAME”. Use the open dialog box to browse to the location of that application.

In order for it to run, it must be saved as run-only, as an application, with the flags for “stay open” and “never show startup screen”
Logged

IIO

  • Staff Member
  • 4096 MB
  • *******
  • Posts: 4824
  • just a number

but is it a good idea to let a clock run in applescript while a game runs?
Logged
insert arbitrary signature here

n8blz

  • 16 MB
  • ***
  • Posts: 22
  • New Member

but is it a good idea to let a clock run in applescript while a game runs?

Good afternoon IIO

I have used it extensively on several games, up to games with high hardware requirements like UT99, Deus Ex, and similar. So far I have not noticed any performance hit, though I have yet to take fps measurements.

I think on OS9 with cooperative multitasking, the “on idle” command makes it sit and do nothing until the running application hands off cpu cycles to the applet? Because the applet seems to be completely passive until the application in question quits. Admittedly it takes a while for it to notice that the application has quit (and to eject the disk image), I have been typing to fine tune that but with little luck so far. But for my purposes, it keeps my kids and their friends from asking “why are there all these icons on the desktop”. Automatic cleanup!

Maybe it’s time to try learning some elementary realbasic and graduate from scripting, but as I have heard many people on the Garden ask for something with this function I thought I would
Logged

IIO

  • Staff Member
  • 4096 MB
  • *******
  • Posts: 4824
  • just a number

unfortunately i know far less about these things than i probably should, as i often have similar ideas and requests. (like opening multiple images at once and saving presets for groups and subgroups pf them)

it seems somehow logical that the script applet must be open all the time - if it also actually does something while waiting for the game to quit, no idea, just trust your test.

isn´t a task like "upon click, mount x.img, wait 15 seconds,then open x.app" what suggest to use a script of type "folder actions"?

if you name your game apps and the associated image files after always the same method (x.img and x.app inside x.folder) the script then could be always the same for different games.

but, as you can probably tell, i am just guessing around.
Logged
insert arbitrary signature here

n8blz

  • 16 MB
  • ***
  • Posts: 22
  • New Member

Do you know, I had never considered using folder actions but you’re right, you could probably have the whole launch process take place upon opening a folder (and the applet could even tidily close that folder back up after). If one preferred that to an applet within the folder (which requires an extra click compared to your idea) the script wording they could use is here in this thread.

The applet must remain open in order to watch for the game to have quit and to then unmount the disk image. What it does while it waits is the question. I understand the “delay” command locks the applet up, such that it can’t be told to quit or anything until the delay period has expired. Feels like using just “delay” would cause that same issue. With the script I have quoted here, the launch/eject applet remains responsive and can be told to quit, while it is sitting there waiting for the game to quit.

I will eventually do an FPS test on the same hardware to confirm, but for now it feels great and now ejection is automatic which was the real pain point I wanted to address. In the interests of making it universal it might be nice to have variables like image name and game executable name pulled from an easily edited text file, and relative paths would mean the directory in which the game and applet live could be freely moved or renamed. And I would like to see the eject of the image occur more rapidly after the game quits. So there is work to be done here!
Logged

IIO

  • Staff Member
  • 4096 MB
  • *******
  • Posts: 4824
  • just a number

i just looked into it for 5 minutes and wanted to make a generic folder script.

how you do deal with image formats?

shrinkwrap understands "mount" via apple events, and toast can normally be reached by the toast mounter extension, which should accept "tell application ... open".

or would you mount them all with the same app?

there could be even .dmg files for OS9 games which would require DC 6.5.x as boss.
Logged
insert arbitrary signature here

IIO

  • Staff Member
  • 4096 MB
  • *******
  • Posts: 4824
  • just a number

wait, one could check for the creator code, then decide how to mount it.

tell application "Finder"
        set creatorCode to creator type of file imagePfad
        if creatorCode is "ROX!" then
            try
                tell application "Toast Mounter" to open file imagePfad
            on error
                display dialog "Toast Mounter konnte das Image nicht laden." buttons {"OK"}
            end try         
        else if creatorCode is "swp " then
            try
                tell application "ShrinkWrap" to mount file imagePfad
            on error
                display dialog "ShrinkWrap konnte das Image nicht mounten." buttons {"OK"}
            end try
           
        else if creatorCode is "dCpy" then
            try
                tell application "Disk Copy" to mount imagePfad with profiles
            on error
                display dialog "Disk Copy konnte das Image nicht mounten." buttons {"OK"}
            end try
           
        else
            try
                open file imagePfad
            on error
                display dialog "Unbekannter Creator-Code (" & creatorCode & "). Öffnen fehlgeschlagen." buttons {"OK"}
            end try
        end if
Logged
insert arbitrary signature here

n8blz

  • 16 MB
  • ***
  • Posts: 22
  • New Member

how you do deal with image formats?

or would you mount them all with the same app?

Good morning IIO

I change the type and creator codes of all image files such that they are mounted with Virtual CD/DVD ROM Utility: https://macintoshgarden.org/apps/virtual-dvd-romcd-utility

There are the occasional image files upon which VCDDVDUtility chokes, but I just use Toast to re-image those image files and presto, no problems.

I also played around a bit with folder scripts. I like how it sort of makes the folder behave like an application package, but… the dealbreaker for me is that little “script” glyph that every folder with a folder script gets. I suppose one could blank out the icon resource for that glyph, but that’s not ideal.

This thread dovetails with another thread I made here earlier, about looking for the perfect launcher. I wanted something that allows double-click launching of any game, and that presents each game as a single, double-clickable, full size, un-glyphed or otherwise uncovered/unmodified, icon. I also wanted the launching system to be read only from the perspective of a child. I settled on using Read Only Disk Copy images, which I can change to read write and modify when needed, which I then place in startup items. The image mounts on the desktop. If the kid trashes the image it returns after restart. Kid can open the image and therein are aliases to each game executable or aliases to these applets, which I re-named and re-icon appropriately. It works perfectly, but CDs staying mounted were the only issue, because they’d make it harder to find the original “launcher” image.

https://macos9lives.com/smforum/index.php?topic=7442.0
Logged
Pages: [1]   Go Up

Recent Topics