Alias (Mac OS)


In classic Mac OS System 7 and later, and in macOS, an alias is a small file that represents another object in a local, remote, or removable file system and provides a dynamic link to it; the target object may be moved or renamed, and the alias will still link to it. In Windows, a "shortcut", a file with a.lnk extension, performs a similar function.
It is similar to the Unix symbolic link, but with the distinction of working even if the target file moves to another location on the same disk. As a descendant of BSD, macOS supports Unix symbolic links as well.

Function

An alias acts as a stand-in for any object in the file system, such as a document, an application, a folder, a hard disk, a network share or removable medium or a printer. When double-clicked, the computer will act the same way as if the original file had been double-clicked. Likewise, choosing an alias file from within a 'File Open' dialog box would open the original file. The purpose of an alias is to assist the user in managing large numbers of files by providing alternative ways to access them without having to copy the files themselves. While a typical alias under the classic Mac OS was small, between 1 and 5 KB, under macOS it can be fairly large, more than 5 MB for the alias to a folder.

Preventing alias failure

An alias is a dynamic reference to an object. The original may be moved to another place within the same filesystem, without breaking the link. The operating system stores several pieces of information about the original in the resource fork of the alias file. Examples of the information used to locate the original are:
Since any of these properties can change without the computer's knowledge, as a result of user activity, various search algorithms are used to find the most plausible target. This fault-tolerance sets the alias apart from similar functions in some other operating systems, such as the Unix symbolic link or the Microsoft Windows shortcut, at the expense of increased complexity and unpredictability. For example, an application can be moved from one directory to another within the same filesystem, but an existing alias would still launch the same application when double-clicked.
The question can arise of how an alias should work if a file is moved, and then a file is created with the same name as the original moved file, since the alias can be used to locate both the original name and the new location of the original file. With symbolic links the reference is unambiguous. Before Mac OS X 10.2, however, such an ambiguous alias would consistently find the original moved file, rather than the recreated file. In Mac OS X 10.2 and later releases, the new file is found, matching the behaviour of symbolic links . macOS applications can programmatically use the old behavior if required.
Aliases are similar in operation to shadows in the graphical Workplace Shell of the OS/2 operating system.

Distinguishing marks

In System 7 through Mac OS 9, aliases distinguished themselves visually to the user by the fact that their file names were in italics. To accommodate languages that don't have italics, in Mac OS 8.5 another distinguishing mark was added, badging with an "alias arrow"—a black arrow with a small white border—similar to that used for shortcuts in Microsoft Windows.
In macOS, the filenames of aliases are not italicized, but the arrow badge remains.

File structure

The alias files in macOS start by the magic number 62 6F 6F 6B 00 00 00 00 6D 61 72 6B 00 00 00 00 which is in ASCII book␀␀␀␀mark␀␀␀␀.
Following the magic number, it has been reported that an alias has a set of records inside it, each record is 150 bytes long and consists of the fields shown below. However, alias files are far larger than this would explain, and include other information at least including icons.
  1. 4 bytes user type name/app creator code = long ASCII text string
  2. 2 bytes record size = short unsigned total length
  3. 2 bytes record version = short integer version
  4. 2 bytes alias kind = short integer value
  5. 1 byte volume name string length = byte unsigned length
  6. 27 bytes volume name string
  7. 4 bytes volume created mac date = long unsigned value in seconds since beginning 1904 to 2040
  8. 2 bytes volume signature = short unsigned HFS value
  9. 2 bytes volume type = short integer mac os value
  10. 4 bytes parent directory id = long unsigned HFS value
  11. 1 bytes file name string length = byte unsigned length
  12. 63 bytes file name string
  13. 4 bytes file number = long unsigned HFS value
  14. 4 bytes file created mac date = long unsigned value in seconds since beginning 1904 to 2040
  15. 4 bytes file type name = long ASCII text string
  16. 4 bytes file creator name = long ASCII text string
  17. 2 bytes nlvl From = short integer range
  18. 2 bytes nlvl To = short integer range
  19. 4 bytes volume attributes = long hex flags
  20. 2 bytes volume file system id = short integer HFS value
  21. 10 bytes reserved = 80-bit value set to zero
  22. 4+ bytes optional extra data strings = short integer type + short unsigned string length
  23. string data = hex dump
  24. odd lengths have a 1 byte odd string length pad = byte value set to zero

    Alias record structure outside of size length

The following is for use with the Apple's Alias Resource Manager.
  1. 4 bytes resource type name = long ASCII text string
  2. 2 bytes resource ID = short integer value
  3. 2 bytes resource end pad = short value set to zero
Java code to flag an alias file

// This function checks whether a file matches the alias magic number.
public static boolean checkForMacAliasFile throws FileNotFoundException, IOException

Managing aliases

User interface

In System 7, the only way to create an alias was to select the original and choose "Make Alias" from the "File" menu. An alias, with the same name and " alias" appended would then be created in the same folder. In later versions, it became possible to create aliases by drag-and-drop, while holding down the command and option modifier keys.
Mac OS 8.5 added a feature for re-connecting aliases that had been broken for one reason or another. This was done by selecting a new target through the standard Open File dialog.
In Mac OS 8.5 options were added for command-option dragging an object in the Finder to create an alias at that location. This is where the alias cursor was added to the system. The cursor mirrors the appearance of the "create shortcut" cursor on Windows systems.

Programming API

The Alias Manager API is part of Carbon. It is unknown whether it was present in Mac OS Classic.
Mac OS X 10.6 introduced some alias-related APIs to Cocoa, as a part of.

Relation to BSD symbolic and hard links

and similar operating systems provide 2 features very similar to macOS aliases: symbolic links and hard links.
When using the macOS Finder, links are displayed and treated largely like macOS aliases, and even carry an identical "Kind" attribute.
However, when using the shell command line, macOS aliases are not recognized: for example, you cannot use the cd command with the name of an alias file. This is because an alias is implemented as a file on the disk that must be interpreted by an API while links are implemented within the filesystem and are thus functional at any level of the OS.
There is currently no pre-installed command to resolve an alias to the path of the file or directory it refers to. However, a freely available C program makes use of the Mac Carbon APIs to perform this task. Given that, commands such as cd can be set up to check for aliases and treat them just like symbolic or hard links.