mounting an image prior to running a game

hi guys, very happy to have joined this excellent forum :slight_smile:

i have just started playing with applescript as i wanted a way to load the disc image of warcraft 3 prior to running the game (dont want to have to put the cd in every time, so i made an iso file in windows (i tried a cdr image using disk utility but it gets errors, so i made the iso in windows using ultraiso))

the applescript i have so far is this:

tell application "Finder"
	open "MacBook HD:Users:SooTyLaD:Library:Disc Images:Warcraft III - The Frozen Throne.iso"
	delay 5
	close Finder window 1
	open "MacBook HD:Applications:Warcraft III:The Frozen Throne"
end tell

the delay is to allow time to mount the image, and the close finder window 1 is to close the autoplay finder popup giving me the installer dialog.

however my problem is that when an image is loaded, i get the following:

http://filebucket.intoeverything.net/discdamaged.png (sorry about this guys i cant get the image to display :frowning:)
and this requires a response to mount the image, if i ignore this, it all goes wrong cuz when the app goes to open, the disc is not yet mounted… any idea how to bypass, or click “open” using actionscript so the whole thing can be automated?

however is there is a simpler and better way to do all this, then please let me know, for example, is there a better way to do the delay bit which involves simply waiting for the disc to be mounted?

i would actually also like it to unmount the image once the game is closed… so if someone could help me out with some decent code that does the following, i would be most grateful :slight_smile:

¢ mount the iso image
¢ once the image is mounted, run the game
¢ once the game is quit, unmount the iso

if someone could code that, it’d be awesome :slight_smile: (and educational ;))

can noone help me out with this? i’m sure its a breeze for you apple gurus?

Hi,

I don’t have WoW so I cannot test this.
Try this version without involving the Finder


set WoWImage to (path to library folder from user domain as text) & "Disc Images:Warcraft III:Warcraft III - The Frozen Throne.iso"
do shell script "hdiutil attach " & quoted form of POSIX path of WoWImage
activate application "The Frozen Throne"

To unmount the Image, you need a stay open application, which poll the processes
something like this


property WoWrunning : false
property WoWmounted : false
property WOWname : "The Frozen Throne"

on idle
	tell application "System Events"
		set WoWrunning to WOWname is in (get name of processes)
		set WoWmounted to WOWname is in (get name of disks)
	end tell
	if WoWrunning is false and WoWmounted then do shell script "hdiutil unmount " & quoted form of ("/Volumes/" & WOWname)
	return 60
end idle

Note: I have no idea at all, how the image and the extracted volume is named. You certainly have to adjust these strings

ok… first up, you’re a genius :wink:

i’ve been having a play and the code is not quite there yet… the image mounts, then the game runs (fantastic!), but once i exit the game, i am greeted with the error:

[i]WC3 Run Script

Connection is invalid.[/i]

from the script, and the image doesn’t dismount…

also, i would like the stay open application itself to close once the dismount has taken place, is this possible?

here is my code so far (changed slightly as i am going to use this script for a few games not just wc3) - saved as a stay open app as mentioned before:

property gameRunning : false
property gameMounted : false
property gameName : "The Frozen Throne"

set gameImage to (path to library folder from user domain as text) & "Installation Files & Disc Images:Games:Warcraft III - The Frozen Throne.iso"
do shell script "hdiutil attach " & quoted form of POSIX path of gameImage
activate application "The Frozen Throne"

on idle
	tell application "System Events"
		set gameRunning to gameName is in (get name of processes)
		set gameMounted to gameName is in (get name of disks)
	end tell
	if gameRunning is false and gameMounted then do shell script "hdiutil unmount " & quoted form of ("/Volumes/" & gameName)
	return 60
end idle

any help in finishing this neat little script off would be greatly appreciated :slight_smile:

here is the latest iteration, this time for diablo II…

now this one sometimes works, but most of the time nothing really happens and i have to force quit the script… when it does work, although it is “stay open” it is not still open when i exit the game, so there is nothing to dismount the image…

i’m sure it just needs some neatening up…

property gameRunning : false
property gameMounted : false
property gameName : "Diablo II (Carbon)"
property gameImageName : "Lord of Destruction"
set gameImage to (path to library folder from user domain as text) & "Installation Files & Disc Images:Games:Diablo II:Diablo II - Lord Of Destruction.iso"

do shell script "hdiutil attach " & quoted form of POSIX path of gameImage
activate application gameName

on idle
	tell application "System Events"
		set gameRunning to gameName is in (get name of processes)
		set gameMounted to gameImageName is in (get name of disks)
	end tell
	if gameRunning is false and gameMounted then do shell script "hdiutil unmount " & quoted form of ("/Volumes/" & gameImageName)
	return 60
end idle

when it doesn’t work (which is actually most of the time), in the activity monitor i can see hdiutil is at maybe 95% cpu and there is also a script icon with the name “(null)” in the 90s… it sticks like this until i force quit the script app, but the hdiutil app stays active (but with minimal cpu usage) and doesn’t quit…

anyone know whats wrong with this code? and also as above i would also like it to quit itself after the dismount…

Hi,

gameImageName must exactly match with the name of the mount point in /Volumes

To quit the script after unmounting the image, try this


.
on idle
	tell application "System Events"
		set gameRunning to gameName is in (get name of processes)
		set gameMounted to gameImageName is in (get name of disks)
	end tell
	if gameRunning is false and gameMounted then
		do shell script "hdiutil detach " & quoted form of ("/Volumes/" & gameImageName)
		quit
	end if
	return 60
end idle

right ok… here is the latest:

property gameRunning : false
property gameMounted : false
property gameName : "Diablo II (Carbon)"
property gameImageName : "Lord of Destruction"
set gameImage to (path to library folder from user domain as text) & "Installation Files & Disc Images:Games:Diablo II:Diablo II - Lord Of Destruction.iso"

do shell script "hdiutil attach " & quoted form of POSIX path of gameImage
activate application gameName

on idle
	tell application "System Events"
		set gameRunning to gameName is in (get name of processes)
		set gameMounted to gameImageName is in (get name of disks)
	end tell
	if gameRunning is false and gameMounted then
		do shell script "hdiutil detach " & quoted form of ("/Volumes/" & gameImageName)
		quit
	end if
	return 60
end idle

now this is a prime example of why i think something isn’t right… when i saved the new version, i ran it and it worked… i exited the game and maybe 30 seconds late the image dismounted, however, the script app didn’t quit.

so i quit it manually, THEN i tried to run it again, and it wouldn’t, just maxes out the cpu cores and does nothing until i force quit…

do you have to kill the process after you’ve finished or something?

Next try


property gameRunning : false
property gameMounted : false
property gameName : "Diablo II (Carbon)"
property gameImageName : "Lord of Destruction"

set gameImage to (path to library folder from user domain as text) & "Installation Files & Disc Images:Games:Diablo II:Diablo II - Lord Of Destruction.iso"
do shell script "hdiutil attach " & quoted form of POSIX path of gameImage
activate application gameName

on idle
	tell application "System Events"
		set gameRunning to gameName is in (get name of processes)
		set gameMounted to gameImageName is in (get name of disks)
	end tell
	if gameRunning is false and gameMounted then quit
	return 60
end idle

on quit
	do shell script "hdiutil detach " & quoted form of ("/Volumes/" & gameImageName)
	continue quit
end quit

very interesting approach (like i originally said i’ve very new to AS so this is very educational for me so thankyou very much StafanK :))

no that one still isn’t working but the problem is lying in the original mounting of the image… if i watch the activity monitor processes, the script app loads, then hdiutil loads (along with two hdiutil-helpe processes), but the hdiutil stays at really high cpu usage and doesn’t do anything else… this then needs to be all force quit…

any ideas?

as a point of interest, and as pat of the quest of finding the perfect code to do this task (:D) - i found another version of what i am trying to do and it has the SAME fault, so maybe it could be useful in diagnosing whats going on…

property diskname : "OED2"
property diskpath : "Macintosh HD:Applications (Mac OS 9):OED2 program:OED2.dmg"
property itemname : "Macintosh HD:Applications (Mac OS 9):OED2 program:OED2 CD-ROM"
property appname : "OED2 CD-ROM"

on run
tell application "Finder"
if not (exists the disk diskname) then
do shell script ("hdiutil attach " & quoted form of ¬
POSIX path of (diskpath as string) & " -mount required")
repeat until name of every disk contains diskname
delay 1
end repeat
end if
open item itemname
end tell
delay 5
end run
-- remainder based on hint by puffyn at macosxhints.com:
-- hint named "Quick Applescript to Mount Disk Image"
-- shell script to get devname by Dale Mox with fixes by jbc 
on idle
set devname to do shell script "mount | grep " & diskname & ¬
" | cut -f1-1 -d \" \" | cut -f3-3 -d \"/\""
tell application "Finder"
if not (exists the disk diskname) then
return
else
set x to the name of every process
if appname is not in x then
do shell script ("hdiutil unmount /Volumes/" & diskname & " -force")
do shell script ("hdiutil detach " & devname & " -force")
tell me to quit
end if
end if
end tell
return 2
end idle

like i said, i get the same problems as before, namely that you run the script and get high 90% cpu usage and nothing else happens and the hdiutil process (the process causing the high cpu usage) needs to be force quit…

is this a leopard thing?

i’m assuming from the lack of replies to the later posts that i have done all that is possible to get it to work… hence i will have to put the project to bed :frowning:

i must say i’m very suprised that this is not possible without hdiutil going crazy and maxing out the cpus and crashing… my first ever applescript, and os x can’t handle it :frowning:

thanks anyway guys…