PDA

View Full Version : launcher script


jmb
03-27-2002, 09:55 PM
Hi,

In order to keep my kids from shoving CDs in and out of our iMac, I have created disk images of their favorite games, and housed them on a big partition of my hard drive. I have also written a simple AppleScript to automate the launch of each game (the scripts are housed in a tab-layer of DragThing). In short, the script looks to see if the .dmg is already mounted. If so, it just launches the game. If not, it mounts the .dmg, then launches the game. I saved it as a run-only application without the startup screen, and it works pretty slick. The only problem is that it opens (and leaves open) extra finder windows. In other words, each of the folders referenced in the 'select file...' statements (see below) are left open after running the script. Being a neat freak, I don't like this. When the game is exited, I want to return to the finder as I left it. My question is this: How can I make it close the windows it opens? It didn't leave these windows open when I did similar things under OS9. Rather, I was able to direct it to a file buried in nested folder, and have it open that file without opening all of the folders. Any other suggestions as to how to improve this script would be greatly appreciated, as well. Thanks!

The script is as follows:

tell application "Finder"

activate

if disk "Rescue Heroes" exists then

select file "Rescue Heroes®" in folder "Rescue Heroes® folder" in folder "Fisher-Price" in folder "Games" of disk "einstein"

open selection

else

select file "Rescue Heroes.dmg" in folder "•CD Images" in folder "Games" of disk "einstein"

open selection

select file "Rescue Heroes®" in folder "Rescue Heroes® folder" in folder "Fisher-Price" in folder "Games" of disk "einstein"

open selection

end if

end tell

xchanyazy
03-28-2002, 06:48 AM
I seem to recall that you can use an HFS-style path to the name, ie

tell application "Finder"

open file "mp3's:Documents:iTunes:iTunes Music:ZZ Top:Eliminator:Sharp Dressed Man.mp3"

end tell


You don't have to select the file, and then open the selection. Just open file, and use the colon seperators (I use a neat program called CopyPath that adds a contextual menu choice to copy either the HFS or UNIX path to the file that is selected. You can find it on versiontracker.com, if you're so inclined) to say where the file is.

EDIT: Stupid :D being a smiley.

jmb
03-28-2002, 12:18 PM
Thanks for your response. I will try it out tonight. Another question cropped up after my initial post. The script I posted above is for a game housed on my hard dirve that needs to access the CD (or disk image, in this case). In some cases, however, the game is housed on the CD (or disk image; it does not install to the HD). In these cases, I am having problems getting the game to launch. It selects and launches the .dmg just fine, but it appears to try and launch the game from the disk image before Disk Copy finishes mounting the .dmg. Therefore, it can't find the game file. The script looks something like this (I have yet to incorporate the suggested changes):


tell application "Finder"
activate
if disk "Whatever" exists then
select file "GameOfInterest" of disk "Whatever"
open selection
else
select file "Whatever.dmg" in folder "•CD Images" in folder "Games" of disk
"einstein"
open selection
select file "GameOfInterest" of disk "Whatever"
open selection
end if
end tell


Again, this differs from the previous script in that file that I am launching is housed on the disk image. Thus, the image must be mounted before I can successfully access the file. This wasn't a problem under OS9 - the image always mounted before the script went onto the next step (opening the file). Thanks for any help or suggestions.

jmb

xchanyazy
03-28-2002, 01:42 PM
Could you throw in a delay x command? Guesstimate how much time it takes for a disk image to open, and then add a couple of seconds to that, then replace x with that number. Your script would look something like this:

tell application "Finder"
activate
if disk "Whatever" exists then
open "Whatever:GameOfInterest"
else
open "einstein:Games:•CD Images:Whatever.dmg"
delay 10
open "Whatever:GameOfInterest"
end if
end tell

jmb
03-28-2002, 04:37 PM
Okay, I'll try that. However, I was just thinking that it should be possible to make the launch statement (open "Whatever:GameOfInterest") contingent on whether or not Disk Copy is open. Because disk copy quits as soon as the image is mounted, the script could then go ahead and launch the game. I'm new to AppleScript, so I have no idea if this is possible, but it sounds like it should be. Any suggestions?

fizikci
06-06-2002, 04:42 AM
jmb,

I think you could also put in a second if command (just like the initial one where you check if disk "whatever" exists") and if it does then go ahead and do the open, else pause a second or two and check again.

-Travis N