Go Back   The macosxhints Forums > Working with OS X > OS X Developer



Reply
 
Thread Tools Rate Thread Display Modes
Old 03-27-2002, 08:55 PM   #1
jmb
Triple-A Player
 
Join Date: Jan 2002
Posts: 92
launcher script

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
jmb is offline   Reply With Quote
Old 03-28-2002, 05:48 AM   #2
xchanyazy
All Star
 
Join Date: Jan 2002
Location: Dexter, MI, USA
Posts: 704
I seem to recall that you can use an HFS-style path to the name, ie
Code:
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.
xchanyazy is offline   Reply With Quote
Old 03-28-2002, 11:18 AM   #3
jmb
Triple-A Player
 
Join Date: Jan 2002
Posts: 92
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):

Code:
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
jmb is offline   Reply With Quote
Old 03-28-2002, 12:42 PM   #4
xchanyazy
All Star
 
Join Date: Jan 2002
Location: Dexter, MI, USA
Posts: 704
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:
Code:
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
xchanyazy is offline   Reply With Quote
Old 03-28-2002, 03:37 PM   #5
jmb
Triple-A Player
 
Join Date: Jan 2002
Posts: 92
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?
jmb is offline   Reply With Quote
Old 06-06-2002, 03:42 AM   #6
fizikci
Prospect
 
Join Date: Jun 2002
Location: WI
Posts: 1
pause option

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
fizikci is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 07:56 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.