How to make an AppleScript use a Folder in the Contents of a Bundle for an alias on the Desktop

aliasapplescriptterminal

I'm trying to write an AppleScript to make a temporary alias on the desktop from a folder that resides in the Bundle's Contents:Resources folder and then execute a terminal command that has an argument from a file that also resides in the Bundle's Contents:Resources folder and then remove the temporary alias from the desktop upon finish or exit.

How do I fix the following code to accomplish this?

set myRes to (path to me as text) & "Contents:Resources:"

tell application "Finder"
     make new alias to folder myRes & "Pass-Through Drive" at desktop
end tell

tell application "Terminal"
     activate
     do script myRes & "BasilliskII --config basilisk_ii_prefs"
end tell

tell application "Finder"
     delete file "Pass-Through Drive" of desktop
end tell

This is the error I get:

error "Can’t make «class cfol» \"Resources\" of «class cfol» \"Contents\" of «class appf» 
  \"Mac OS 8.1.app\" of «class cfol» \"Desktop\" of «class cfol» \"ryan\" of «class cfol»
  \"Users\" of «class sdsk» of application \"Finder\" into type list, record or text."
  number -1700 from «class cfol» "Resources" of «class cfol» "Contents" of «class appf» 
  "Mac OS 8.1.app" of «class cfol» "Desktop" of «class cfol» "ryan" of «class cfol» "Users"
  of «class sdsk» to list, record or text

I think I've corrected it down to…

set myRes to (path to me as text) & "Contents:Resources:"

tell application "Finder"
     make new alias to folder (myRes & "Pass-Through Drive") at desktop
end tell

tell application "Terminal"
     activate
     do script myRes & "BasilliskII --config " & myRes & "basilisk_ii_prefs"
end tell

tell application "Finder"
    delete file "Pass-Through Drive" of desktop
end tell

but still having trouble with the middle lines and the proper syntax of what I'm trying to accomplish.

Best Answer

You don't need to tell Terminal to run the script (unless you just want to lay eyes on it). But also you'll want to use a posix path escaped to prevent errors.

You could do it like ...

set myRes to alias (path to me as text) & "Contents:Resources:"

tell application "Finder"
     make new alias to folder (myRes & "Pass-Through Drive") at desktop
end tell

set posixRes to (POSIX path of myRes)

do shell script quoted form of posixRes & "BasilliskII --config " & quoted form of posixRes & "basilisk_ii_prefs"

tell application "Finder"
    delete file "Pass-Through Drive" of desktop
end tell