Passing path within "do shell script"

I am trying to write an AppleScript app bundle that runs a shell command. The command is not installed, so I have bundled the command inside an AppleScript app bundle like so:
myasbundle.app/Contents/Resources/Commands/mycommand

When I originally wrote the main.scpt for this app bundle, I called the command using “do shell script” and it’s absolute path":
do shell script “‘/Volumes/Macintosh HD/myasbundle.app/Contents/Resources/Commands/mycommand’”
This causes the app to break if it is not located within this exact path, if the HD name is different, etc.

How do I set and pass a variable so that the main.scpt always looks in “Contents/Resources/Commands” within it’s app bundle? This way I can place myasbundle.app anywhere on the filesystem and it will still execute correctly.

Try this:

set myCommand to POSIX path of (path to resource "mycommand" in directory "Commands")
do shell script myCommand

See also: Calling to Files within a Bundle or App.

Thanks for the response.
I tried your suggestion, and get the error “resource not found”.
Here is the relevant bundle contents in case I didn’t explain it very well:

myasbundle.app/Contents/Resources/Sctipts/main.scpt
myasbundle.app/Contents/Resources/Commands/mycommand
myasbundle.app/Contents/Resources/Commands/mysourcefile

when placing your code in main.scpt:

  • set myCommand to POSIX path of (path to resource “mycommand” in directory “Commands”)

I get a “resource not found” error

So I tried the other method listed in your attached post:

  • set myCommand to POSIX path of ((path to me as string) & “Contents:Resources:Commands:mycommand”)
    which works, except my “do shell script” command needs 3 parts:
  • do shell script myCommand /somedirectory mySourcefile
    and I can’t get the formatting right to use this.

Here is my main.scpt in it’s entirety:

  • set myCommand to POSIX path of ((path to me as string) & “Contents:Resources:Commands:mycommand”)
  • set mySourcefile to POSIX path of ((path to me as string) & “Contents:Resources:Commands:mysourcefile”)
  • do shell script myCommand /somedirectory mySourcefile

As you can see, both the myCommand and mySourcefile are variables, but the /somedirectory is not. Originally, my do shell script command looked like the example listed in my first post, where I quoted an entire command within one line:
do shell script “‘/path/to/mycommand’ ‘/path/to/directory/target’ ‘/path/to/mysourcefile’”
Since /path/to/mycommand & /path/to/mysourcefile have been replaced by applescript variables, how do I quote this line correctly within my main.scpt?

I’m sorry if I sound like a newbie, because I am. Thanks for your help in advance! (BTW, the usage of the “-” in front of lines just signifies a line of code, and is not in the line of code!)

Try this:

set myCommand to POSIX path of ((path to me as string) & "Contents:Resources:Commands:mycommand")
set mySourceFile to POSIX path of ((path to me as string) & "Contents:Resources:Commands:mysourcefile")
set targetDirectory to "/path/to/directory/target"

do shell script (quoted form of myCommand) & (quoted form of targetDirectory) & (quoted form of mySourceFile)