Technical Q&A QA1493

How do I access files contained in my AppleScript Studio application's main bundle?

Q:  How do I access files contained in my AppleScript Studio application's main bundle?

A: How do I access files contained in my AppleScript Studio application's main bundle?

If you have files in your AppleScript Studio application's bundle (that is, in your Resources folder under Groups & Files (see Figure 1), you can access them by using "resource path of main bundle" plus the pathname hierarchy to the file. See Listing 1 for an example.

Figure 1  Groups & Files showing pathname hierarchy.

Listing 1  Using 'resource path of main bundle'

set myFile to (resource path of main bundle) & "/path/to/your/file.txt"

When you run this, myfile would contain a path similar to "/Users/username/AppleScript Studio.app/Contents/Resources/path/to/your/file.txt". (This path would likely include ".../build/Debug" when testing within Xcode.)

For more information on bundles in AppleScript Studio, see the Application Suite > Terminology > bundle section of "AppleScript Studio Terminology Reference"; you can find it in the ADC Reference Library at Reference > AppleScript > Tools.



Document Revision History


DateNotes
2007-02-05

Clarified pathname hierarchy references; added pointer to reference guide.

2006-10-09

New document that explains how to access files stored within an AppleScript Studio application.