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 846 times)

n8blz

  • 16 MB
  • ***
  • Posts: 21
  • 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: 21
  • 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: 4822
  • 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: 21
  • 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: 4822
  • 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: 21
  • 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
Pages: [1]   Go Up

Recent Topics