Can somebody point me to a good explanation of file aliases?

I’m what you might call an “advanced beginner” at AS, and though I’ve seen file aliases used and read some bits about them, I can’t seem to wrap my mind around exactly how and when to use them.

Is there a tutorial on this subject that could help me? TIA.

It is almost never a bad idea to use them in your scripts because they are “generic” references to a file or folder. Finder references are only useful to the Finder. I’ve never seen a tutorial on that, but I’m sure someone more knowledgible than I about the details will weigh in.

Hi, Rob.

An alias is a particular way of referring to a file, a folder, or a disk in AppleScript. Its written form in a script is the keyword ‘alias’ followed by a path in HFS format.

alias "Disk name:Folder name:Subfolder name:Sub-subfolder name:File name"

When it’s hard-coded, as above, all the folders and files concerned must exist at the time the script’s compiled, otherwise the compiler won’t be able to create the alias. An alternative is to put the path text into a variable, in which case the folders and files will only have to exist when the reference is used at run time:

set myPath to "Disk name:Folder name:Subfolder name:Sub-subfolder name:File name"
alias myPath

An alias has the property that if, after it’s created, the item to which it refers is either moved to another location or renamed, the alias will keep track of it and will still refer to it.

Aliases can be used by, and freely exchanged between, vanilla AppleScript, scripting additions, and applications.

The term ‘alias’ shouldn’t be confused with ‘alias file’, which is a Finder scripting term for the kind of file called an “alias” which acts as a proxy for a “real” file, folder, or disk.

Vanilla AppleScript also has a ‘file’ form, which, like an alias, can refer to either a file, a folder, or a disk:

file "Disk name:Folder name:Subfolder name:Sub-subfolder name:File name"

The item referred to by a ‘file’ reference needn’t exist when the script’s compiled and, depending on the context, may not even need to exist when the reference is used at run time. A ‘file’ always points to the same location, so if the item in that location’s subsequently moved or renamed, the ‘file’ reference will lose track of it.

An AppleScript ‘file’ is understood by vanilla AppleScript, scripting additions, and most applications. However, some applications ” notably the Finder and System Events ” have their own underlying codes and rules corresponding to the ‘file’ keyword, which are incompatible with the vanilla form and with each other and can’t be passed around between contexts.

It’s become quite common for a path itself to be understood to mean an AppleScript ‘file’, mainly because people coming from other languages have been confused when it wasn’t. But strictly speaking, a path is just text. It’s better AppleScript to use a proper specifier with the ‘file’ keyword.

Hope some of that’s what you wanted to know. :slight_smile: