Applescript - Unable to find resource when inside application
There are a few reasons it didn't work.
-
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." - Applescript uses its own (stupid) file path syntax, so you need the POSIX version.
- It breaks on spaces because appending the POSIX path
~/Desktop/test folder
shows up as 2 arguments tobash
. To fix this just put quotes around it, as you would any other time, withquoted 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.