Language Guide
CHAPTER 5
Objects and References
144 References to Files and Applications
References to Files 5
You can use either of these forms to refer to any file:
file nameString
alias nameString
where
nameString is a string of the form "Disk:Folder1:Folder2:...:Filename" that
specifies exactly where the file is stored or a string that consists of the file’s
name only. Disk specifies the disk on the local computer on which the applica-
tion is stored, Folder1:Folder2:... specifies the sequence of folders that you
would have to open to find the application on the local computer, and fileName
specifies the name of the file. AppleScript doesn’t distinguish uppercase letters
from lowercase letters in filenames.
If nameString consists of the file’s name only, AppleScript attempts to locate the
file in the current directory for the application from which the script is being
run (for example, Script Editor). The current directory is the folder or volume
whose contents you can see when you choose Open or the equivalent
command from the application’s File menu. By default, the current directory
for any application is the folder or volume in which the application is stored;
but the current directory may change as you open and close files and folders
from within the application. To be sure that a command acts on the correct file,
specify the entire pathname, including the names of the volume and the entire
sequence of folders that you would have to open to find the file.
If you use a reference of the form file nameString, AppleScript doesn’t
attempt to locate the file until the script is actually run. When the script is
run, the file must be located in the specified folder (or, if only a filename was
provided, in the current directory) for AppleScript to locate it successfully.
Some commands, such as the Save command, create a file with the specified
name in the specified location if it doesn’t already exist.
To save a reference of the form file nameString in a variable, you must use the
A Reference To operator as shown in the example that follows. (To use this
script successfully, substitute a pathname that corresponds to a volume, folder
or folders, and file that actually exist on your computer.)