Language Guide
CHAPTER 5
Objects and References
References to Files and Applications 145
set fileRef to a reference to file "Hard Disk:June Sales"
tell application "Scriptable Text Editor"
open fileRef
end
If you use a reference of the form alias nameString, AppleScript creates an
alias for the file—that is, a representation of the file, much like an alias icon on
the desktop, that identifies the file no matter where it is located. AppleScript
attempts to locate the file whenever you compile the script—that is, whenever
you modify the script and then attempt to check its syntax, save it, or run it.
AppleScript treats an alias like a value that can be stored in a variable and
passed around within a script. You don’t need to use the A Reference To
operator. For example, this script first saves an alias in the variable fileRef,
then uses the variable in a Tell statement that opens the file.
set fileRef to alias "Hard Disk:June Sales"
tell application "Scriptable Text Editor"
open fileRef
end
If you save this script as a script application or compiled script, move the file
June Sales to another location, then open the script again, the statement alias
"Hard Disk:June Sales" or its equivalent changes to reflect the file’s new
location, and the script still works correctly.
The difference between the forms file nameString and alias nameString is
also apparent when the file in question is located on a remote computer. If you
use the form file nameString, AppleScript doesn’t attempt to locate the file
until you actually run the script. If you use the form alias nameString,
AppleScript also attempts to locate the file whenever you compile the script,
requiring appropriate access privileges and possibly a password each time.
The actions you can perform on a specific file depend on the way the applica-
tion that created the file defines a file object. If an application provides its own
definition for a file object, AppleScript locates the file as described in this
section, but uses the definition in the application’s dictionary to determine the
characteristics of the object, such as its properties and the commands it can
handle. For the Scriptable Text Editor’s definition of a file, see page 328.