I have a regular Applescript application bundle that executes an applescript file when it's run. I'm trying to run a shell file that is located at "/Contents/Resources/Data/df.sh", however with the code I'm using, it keeps giving me "resource not found" errors.

set bashFile to path to resource "df.sh"
do shell script "bash " & bashFile

I'm really new to Applescript, so there's the chance I'm doing something obvious wrong.

4 Answers 4


There are a few reasons it didn't work.

  1. path to resource basically takes the bundle path and finds files in there, so you need to actually put the subdirectory, in this case "Data."
  2. Applescript uses its own (stupid) file path syntax, so you need the POSIX version.
  3. It breaks on spaces because appending the POSIX path ~/Desktop/test folder shows up as 2 arguments to bash. To fix this just put quotes around it, as you would any other time, with quoted form of.

Here's the fixed script:

set bashFile to path to resource "Data/df.sh"
do shell script "bash " & quoted form of (POSIX path of bashFile)

I am unable to comment yet, but there was 1 more tip that helped me. In addition to 0942v8653's answer:

  • For example, if you are using the Script Editor (and possibly the Automator app as well), close and re-open the program.

I had added the file outside of the program, so it must not have loaded/recognized the file until I restarted it.

  • There is also a similar effect when working with the Keychain Access application, just to mention how some common first-party applications act on the OS X platform.
    – Pysis
    Jun 9, 2016 at 17:35

The file you are trying to execute— if you locate it in the Finder and Get Info on it Command I, what path does the info window say under "Where:". That is most probably the path you will want to use.

  • No. There's a reason I'm doing it like this. If I do your method, when the application gets moved to somewhere else the file path breaks. I'm trying to do it so that it always works regardless of the bundle location. Feb 19, 2014 at 9:34

Try using path to me instead:

do shell script "bash " & POSIX path of (path to me) & "Contents/Resources/script.sh"

((path to me as text) & "Contents:Resources:script.sh") as alias

  • It edited my code to include that, but it seems that it gets tripped up when a space occurs in the file path. e.g.: "bash: /Users/user1/Desktop/test: No such file or directory" when the folder is actually called "test folder". Feb 19, 2014 at 13:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .