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.
AppleScript – Difference Between HFS Path and Alias Path
applescriptpath
Related Question
- AppleScript – Copy Path and Name to Spotlight Comment Box in macOS
- AppleScript – Recreate Alias with Same Name and Timestamp Programmatically
- Difference Between AppleScript Version and AppleScript Studio Version
- macOS Terminal – Difference Between Filename and .Filename
- The difference between `on` and `to` in AppleScript handler declaration
- Applescript problems with renaming a file and getting the alias to change it’s name as well
Best 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:versus
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 andreveal
it (which, of course, throws an error, because the command makes no sense).An
alias
is a type of object specifier just likefolder
, 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:"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 thealias
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 analias
construct. It does not, however, infer that any HFS path must also be a so-called "alias path", which makes no sense without the accompanyingalias
specifier, in exactly the same way it makes no sense to Finder without afolder
specifier.Paths
In a general computing context, a path is defined by Wikipedia as:
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:
which, of course, it doesn't, because it returns an
alias
object, not a path.This, however:
does return a path, because the
alias
object has been coerced totext
, 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 analias
object; to infer that the second example must also be an "alias path" is incorrect, as it now lacks thealias
object specifier.alias
ObjectsSimply, an AppleScript
alias
object is:And, notably:
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 thealias
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:
and, in System Events, we can see the
alias
object has two properties of note, one being thepath
property, which returns the HFS path in text format; and the other beingPOSIX 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.