This was brought up in a comment from another question/answer and I was curious what is the difference between an HFS path and an alias path. My understanding they were the same.
1 Answer
I believe that there's been some confusion, both in the current understanding of the OP, and reinforced by the answer given by oa-, which has offered an opinion, but not one that is supported by any of the links provided (the answer has since been deleted).
It's clear we all understand what an HFS path is in the broad sense, that is a path that separates its folders using a colon delimiter, e.g.Macintosh HD:Users:CK:Desktop:
. Similarly, we all understand that there is another format, called a posix path, that uses a slash as directory delimiters, e.g. /Users/CK/Desktop/
.
However, the confusion I'm seeing is in the use of the term alias
(in an AppleScript context), and how this does or does not relate to HFS paths.
Object Specifiers in AppleScript
AppleScript uses object specifiers to distinguish different object types from one another. For example, the folder
object specifier tells Finder that "Macintosh HD:Users:CK:Desktop:"
denotes a folder object on the filesystem, and not simply a string that has no context by itself:
tell application "Finder" to reveal the folder "Macintosh HD:Users:CK:Desktop:"
versus
tell application "Finder" to reveal "Macintosh HD:Users:CK:Desktop:"
the former illustrating the use of the folder
object specifier to correctly form a reference to an AppleScript object, while the latter asking Finder to take a string object and reveal
it (which, of course, throws an error, because the command makes no sense).
An alias
is a type of object specifier just like folder
, and it is used to construct an AppleScript object that references a file or folder on the filesystem by supplying it with a name specifier, which evaluates to the path of the item on the filesystem:
"You can create alias objects and file objects by supplying a name specifier, where the name is the path to an item in the file system."
AppleScript Language Guide - Specifying Paths
"Alias path"
Note that the term "alias path" does not officially exist in an AppleScript context, and it is one that has arisen out of convenience, but actually refers to an alias
object rather than a path.
What is true is that the path supplied as a name specifier for an alias
object must be an HFS path, and for this reason, AppleScripters often refer an "alias path" as shorthand for the alias
object's name specifier. It is a colloquial term that works in one direction only, which is when referring to an HFS path whilst wrapped inside an alias
construct. It does not, however, infer that any HFS path must also be a so-called "alias path", which makes no sense without the accompanying alias
specifier, in exactly the same way it makes no sense to Finder without a folder
specifier.
Paths
In a general computing context, a path is defined by Wikipedia as:
"A path, the general form of the name of a file or directory, specifies a unique location in a file system. A path points to a file system location by following the directory tree hierarchy expressed in a string of characters in which path components, separated by a delimiting character, represent each directory."
Wikipedia - Path (computing)
A computer-science definition for path usually generalises this slightly to specify a path as any sequence or list of symbols and names that tell an operating system how to locate a file, to which the path leads.ref: 1 2 3
In either case, the nature of a path is, as Wikipedia states, expressed almost always as a string of characters.
Simply put, a path is a string, and in the AppleScript context, this is always the case.
More Than Semantics
This can all be dismissed as mere semantics to a casual reader, until situations arise, such as the one that originally spurred the OP to post this question. Quoting from an answer to another question here:
path to desktop folderwould return an HFS path
which, of course, it doesn't, because it returns an alias
object, not a path.
This, however:
(path to desktop folder) as text
does return a path, because the alias
object has been coerced to text
, and the type of path it returns is an HFS path.
Therefore, whilst the alias
object returned by the first example is sometimes referred to as an "alias path", taking into account its nature as an alias
object; to infer that the second example must also be an "alias path" is incorrect, as it now lacks the alias
object specifier.
alias
Objects
Simply, an AppleScript alias
object is:
"An alias object dynamically points to an existing item in the file system."
Mac Automation Scripting Guide - Referencing Files and Folders - Alias Objects
And, notably:
"An alias object is displayed as a colon-delimited path preceded by an alias specifier."
Mac Automation Scripting Guide - Referencing Files and Folders - Alias Objects
which explicitly defines the two components that make up an alias
object's definition, being the colon-delimited (HFS) path (i.e. the name specifier, which is a string), paired with the alias
object specifier.
What this does is construct an AppleScript object that is much more than just a simple path, and serves as a construct to house lots of different properties of the filesystem item it references, one of which, of course, includes the path to the item.
These properties can be enumerated by both Finder and System Events like so:
tell application "System Events" to get the properties of (path to desktop folder)
and, in System Events, we can see the alias
object has two properties of note, one being the path
property, which returns the HFS path in text format; and the other being POSIX path
property, which returns the posix path in text format.
Conclusion (or TL;DR)
"Alias path" is a vernacular that, in an AppleScript context, can refer to the path of a filesystem item to which an
alias
object references, but can also refer to thealias
object itself. Therefore, despite what the name implies, an "alias path" is not necessarily, itself, a path;A path is a string that contains directions through a directory structure to a file item on the filesystem;
An
alias
object is, itself, not a path, but does contain path information, and it stores and displays this in HFS format;An "alias path" will, indeed, be an HFS path (or contain path information as such); an HFS path, however, is not an "alias path".
It's best to avoid using confusing/conflicting terminology, especially in answers on Stack Overflow that are to be read by newcomers to AppleScript or scripting in general. "Alias path" is one of these, as it is not an officially recognised AppleScript term, and clearly has proven to cause confusion. Therefore, refer instead to "alias objects" and "paths" as distinct entities, the latter of which can be an "HFS path" or a "posix path" in string format that pairs with an object specifier to create an AppleScript file reference object.
-
1Excellent answer, +1 and should definitely be marked as the accepted answer! FWIW I'd set in bold the paragraph just before "
alias
Objects" or at least set bold "to infer that the second example must also be an "alias path" is incorrect". BTW... "forward slashes"? No, generally speaking and singularly, the proper term is slash, and there are the backslash and slash, but no "forward slash" character. So a POSIX path uses the slash character to delimit the hierarchal directory structure, not a "forward slash". Dec 3, 2018 at 13:06 -
1Thank you for your very clear answer! @ʀ2ᴅ2 , please mark this as the correct answer.– oa-Dec 4, 2018 at 11:07