Need help with small AppleScript

applescript

I'm on Yosemite 10.10.4, Mac Mini.
I have a small Bash shell script to start Quake3 Arena in Wine. It works fine.

#ยก/bin/bash
cd Desktop/Quake3ISO
hdiutil mount "Quake 3 Arena.iso"
cd Quake3
wine quake3.exe

Line 2: cd to the folder on my desktop that contains the iso, and also extracted files from the iso. I know it's a mess, but its the only way I can get it to work.

Line 3: mount the iso

Line 4: cd to a folder within the first one, called Quake3

Line 5: run "wine quake3.exe" which lives in that directory. (Desktop/Quake3ISO/Quake3)

So, trying ./quake3.sh mounts the iso, and runs the program happily.

But…
I am trying to do the same in AppleScript, but it's failing to find the configuration file for quake3.
It loads the image, and changes directories, runs wine and begins quake, but it now can't find the configuration directory, and possibly a few other files. The configuration directory is also below that (Desktop/Quake3ISO/Quake3/baseq3) folder

Q3 1.11 win-x86 Nov 24 1999
----- FS_Startup -----
Current search path:
Z:\Users\robert/baseq3

----------------------

Running in restricted demo mode.

----- FS_Startup -----
Current search path:
Z:\Users\robert/demoq3

----------------------
----- CL_Shutdown -----
-----------------------
Couldn't load default.cfg

I forgot to add. My Applescript

tell application "Terminal"
    activate
    do script "cd ~/Desktop/Quake3ISO"
    do script "hdiutil mount ~/Desktop/Quake3ISO/Quake\\ 3\\ Arena.iso"
    delay 5
    do script "cd ~/Desktop/Quake3ISO/quake3"
    do script "wine ~/Desktop/Quake3ISO/quake3/quake3.exe"
end tell

After some more experimentation I discover the following. As usual with QuakeIII, the CD has to be in the drive. So mounting it seems to fix that.
Next, I had done an install in the ~/Desktop/Quake3ISO directory, but a few years back had also done a wine install – which would not run.
But just now I copied all the files in the ~/Desktop/Quake3ISO/Quake3/baseq3 folder to the wine install folder in ~/.wine/drive_c/Program\ Files/Quake\ III\ Arena/baseq3 folder, and now I can run Quake directly from that wine folder.

   ie
    cd "/Users/robert/.wine/drive_c/Program Files/Quake III Arena"
    wine quake3.exe

and it runs fine.

I can also so the same in the ~/Desktop/Quake3ISO/Quake3 folder

ie
cd ~/Desktop/Quake3ISO/Quake3
wine quake3.exe

… and it runs fine.

So this tells me that I need to have AppleScript understand that the command to be executed should be executed in the directory it's changed to. So that when the program is looking for it's config files, it uses that directory as the base, or root directory and not the wine base directory? I think?

Best Answer

Every do shell script command starts a new shell, so the cd doesn't have any impact on the following command. So you would be better of with running

tell application "Terminal"
    activate
    do shell script "cd ~/Desktop/Quake3ISO && hdiutil mount ~/Desktop/Quake3ISO/Quake\\ 3\\ Arena.iso"
    delay 5
    do shell script "cd ~/Desktop/Quake3ISO/quake3 && wine ~/Desktop/Quake3ISO/quake3/quake3.exe"
end tell