Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Macintosh Toolbox Essentials /
Chapter 7 - Finder Interface / Using the Finder Interface


Using Aliases

The Finder allows the user to create multiple icons to represent a single document or other desktop object (such as a disk, a folder, or the Trash). One of the icons represents the actual file; the others are aliases that point to the file. An alias is an object that represents some other file, directory, or volume. An alias looks like the icon of its target, but its name is displayed in a different style. The style depends on the system script; for Roman and most other scripts, alias names are displayed in italic.

To the user, the icons of the actual file and its aliases are functionally identical. Aliases give the user more flexibility in organizing files and offer a convenient way to store a local copy of a large or dynamic file that resides on a file server.

Ordinarily, when the user wants to open or print files, your application does not need to be concerned with whether they are aliases because both the Finder and the Standard File Package resolve aliases before passing them to your application. If the user opens an alias that represents a document created by your application, the Finder passes your application the name and location of the document itself, not the alias. Similarly, when the user opens an alias from within your application, the Standard File Package passes your application the name of the target document.

If your application opens a file or a directory without going through the Finder or the Standard File Package (if, for example, it uses preference files or dictionary files), your application should always call the ResolveAliasFile function just before opening
the file.

As a Finder object, the alias depicts a file called the alias file, which contains a record that points to the file, directory, or volume represented by the icon. Alias files are created and managed by the user through the Finder.

Although your application shouldn't create alias files or change users' aliases, your application can create and use its own alias records for storing identifying information about files or directories. An alias record is a data structure that identifies a file, folder, or volume. Whenever your application needs to store file or directory information, you can record the location and other identifying information in an alias record. The next time your application needs the file or directory, you can use the Alias Manager to locate it, even if the user has renamed it, copied it, restored it from backup, or moved it. You can also use alias records to identify objects on other volumes, including AppleShare volumes. See the chapter "Alias Manager" in Inside Macintosh: Files for details about creating and managing information in alias records.

An alias file contains an alias record, stored as a resource of type 'alis', that points to the target of the alias. (The alias target is the file, directory, or volume described by the alias record.) The alias file might also contain the target object's icon descriptions. The Finder identifies an alias file by setting the isAlias bit in the file's Finder flags field (see "File Information Record" beginning on page 7-44 for a description of Finder flags).

An alias file that represents a document typically has the same type and creator as the file it represents. However, many Finder objects--such as disks, folders, and the Trash--do not have file types. Instead, alias files for these objects are assigned special file
types, called alias types. Here are the alias types for those objects for which users can create aliases:
ObjectAlias typeConstant
Apple Menu Items folder
'faam'

kAppleMenuFolderAliasType
AppleShare drop folder'fadr'kDropFolderAliasType
Application'adrp'kApplicationAliasType
Control Panels folder'fact'kControlPanelFolderAliasType
Exported
AppleShare folder

'faet'

kExportedFolderAliasType
Extensions folder'faex'kExtensionFolderAliasType
File server'srvr'kContainerServerAliasType
Floppy disk'flpy'kContainerFloppyAliasType
Folder'fdrp'kContainerFolderAliasType
Hard disk'hdsk'kContainerHardDiskAliasType
Mounted
AppleShare folder

'famn'

kMountedFolderAliasType
Other objects that
can hold files

'drop'

kContainerAliasType
Preferences folder'fapf'kPreferencesFolderAliasType
PrintMonitor
Documents folder

'fapn'

kPrintMonitorDocsFolderAliasType
Shared
AppleShare folder

'fash'

kSharedFolderAliasType
Startup Items folder'fast'kStartupFolderAliasType
System Folder'fasy'kSystemFolderAliasType
Trash'trsh'kContainerTrashAliasType

(The Extensions, Preferences, Apple Menu Items, Control Panels, Startup Items, and PrintMonitor Documents folders are described in "Using the System Folder and Its Related Directories" beginning on page 7-39.)

When opening a file without going through the Finder or the Standard File Package,
you call ResolveAliasFile immediately before opening the file. (The ResolveAliasFile function is described in detail on page 7-49.) In Listing 7-13,
the customized open function MyOpen ensures that the file to be opened is the target
file and then opens the data fork with the File Manager function FSpOpenDF.

Listing 7-13 Using the ResolveAliasFile function to open a file

FUNCTION MyOpen (VAR theSpec: FSSpec; perm: SignedByte; 
                 VAR fRefNum: Integer): OSErr;
VAR
   myErr:            OSErr;
   targetIsFolder:   Boolean;
   wasAliased:       Boolean;
BEGIN 
   myErr := ResolveAliasFile(theSpec, TRUE, targetIsFolder, wasAliased);
   IF targetIsFolder THEN
      myErr := paramErr                {cannot open a folder}
   ELSE IF (myErr <> noErr ) THEN      {try to open it}
      myErr := FSpOpenDF(theSpec, perm, fRefNum);
   MyOpen := myErr;
END;

Previous Book Contents Book Index Next

© Apple Computer, Inc.
11 JUL 1996