I\'m trying to load some .applescript files in my project.
Copied them into the \"Supporting Files\" directory like this:
In addition to what Zaph said, be sure that you are not running in 'Release' mode.
There was a time where I forgot to change that setting back, and the symbols were stripped, thus making NSBundle incapable of resolving the path.
For all those who are still getting a nil path and the file is added in "Copy Bundle Resources" just remove the file from Copy Bundle Resources and than add again.
Great response from Zaph above, but I noticed when I was doing it there's quicker way, at least in Xcode 6.1.
if you single click the file (eg. test.applescript) and have the right menu of Xcode open, you'll see a section called "Target Membership". Make sure that the right target (as in the one you're using the script with) is selected and it'll do the same job as adding the file under "Copy Bundle Resources"
Also, not entirely relevant but in case you're loading from several different places, or you are inheriting this class. You shouldn't really use
[NSBundle mainBundle];
instead use
[NSBundle bundleForClass:[self class]];
That means you don't have to worry about where you are on the method call it'll take the resource from the appropriate items associated with the target you're running. Great for making libraries and reusable calls ;)
Does your image assume that that file in some folder?
Try pathForResource:ofType:inDirectory:
method in this case:
NSLog(@"Resource path for test.applescript: %@", [bundle pathForResource:@"test" ofType:@"applescript" inDirectory:@"folder/Supporting Files");
In the Xcode target "Build Phases" add the file under "Copy Bundle Resources"".