An open community 
of Macintosh users,
for Macintosh users.

FineTunedMac Dashboard widget now available! Download Here

Topic Options
#46844 - 11/13/17 10:04 AM The Name of an Alias
Ira L Offline


Registered: 08/13/09
Loc: California
Let's say I have a file named "ABC.pdf". I create an alias, which by default is named "ABC.pdf alias".

Questions:
1. If I change the name of the alias to "XYZ.pdf alias" (nothing else has that name), will it still point to ABC.pdf?
2. If I change the name of ABC.pdf to XYZ.pdf and keep the alias as "ABC.pdf alias", will it still point to the newly named XYZ.pdf?

My thinking is that alias references are name independent and using something else to make the connection. Yes, I could do the checking myself, but would like a more technical resolution to my questions. Thanks.

Not interested in using a symbolic link at this time.
_________________________
On a Mac since 1984.
Currently: 27" iMacs, Macbook Air, macOS 10.14.x,; iPhones, iPods and iPads galore!

Top
#46845 - 11/13/17 11:49 AM Re: The Name of an Alias [Re: Ira L]
Urquhart Offline


Registered: 08/10/17
Loc: Netherlands
Yes and Yes, even both.
When you create an alias for an object, the system creates a small data file that includes the current path to the object, as well as the object's inode name. Each object's inode name is a long string of numbers, independent of the name you give the object, and guaranteed to be unique to any volume or drive your Mac uses. [1] The latter guarantees that it still works if either one or both names and location changes.

Note that aliases are resolved by the Finder, so Terminal may give unexpected results.

Top
#46851 - 11/14/17 12:27 PM Re: The Name of an Alias [Re: Ira L]
Virtual1 Offline


Registered: 08/04/09
Loc: Iowa
when you create an alias, the Finder makes a document and interestingly enough, a resource fork, to contain an ALIS resource. As was previously mentioned, contains a string path to the file as well as the device guid + device inode of the file or folder. Either one of these is often enough to find a file, and any app that uses the mac os APIs to resolve it will have no problem with it. Terminal commands don't support aliases, but translation IS possible. If you rename a file, OR a folder / drive in the path of the file, and then try to use the gui to access it, it will discover one mode is invalid, and will use the other good mode to fix the first one, and then access the file normally.

If you change BOTH the inode AND the path, the alias will break. You already know how to change the path, but to change the inode simply make a different file by the same name in a different folder, and drag it into the original's folder. Finder will prompt you and you can replace it. Same path, different inode. If you then rename the file, you have changed its path and its inode, and any alias to it is now broken.

Terminal uses hard and soft symbolic links instead. Soft symbolic links are just the path part of an ALIS. Hard symbolic links are duplicate directory entries for the same inode, and so they're like the inode half of the ALIS, but can't cross volumes. The OS is weird with hard links... a file isn't truly deleted until ALL of the hard links (including the original one) are removed - if any of them exist, the file still exists. You can overwrite and replace a file all day long and soft ("symbolic") links to it will continue to work. You can rename or move a file all day long (or even rm it!) and hard links to it will continue to work. So each has its own specific advantages.

This applescript (callable in terminal with osascript) uses Finder to get the unix path of a Finder alias, which you can use to make or replace it with a hard or soft link.

tell application "Finder"
set theItem to (POSIX file "'${item_path}'") as alias
if the kind of theItem is "alias" then
get the posix path of (original item of theItem as text)
end if
end tell

I've seen a way to create a finder alias from a path (the reverse of the above) but I don't see it offhand here. Maybe buried in the sands of time?

It's interesting to see that Finder icons and aliases are really the only two resource fork resource types still actively in use in mac os.

oh also, in most cases when you access an alias with Finder, (cmd-click on it, or get info etc) mac os checks to see if the target's icon has changed. if it has, it usually changes the alias's icon to match it. Otherwise alias icons don't change when their target does.
_________________________
I work for the Department of Redundancy Department

Top
#46852 - 11/14/17 12:44 PM Re: The Name of an Alias [Re: Virtual1]
artie505 Offline


Registered: 08/04/09
Great post! Thanks. smile

Aliases and symbolic links have been discussed before, but this explanation includes new facts that have expanded my understanding of the subject.
_________________________
The new Great Equalizer is the SEND button.

In Memory Of Harv: Those who can make you believe absurdities can make you commit atrocities. ~Voltaire

Top
#46855 - 11/14/17 03:11 PM Re: The Name of an Alias [Re: Virtual1]
Ira L Offline


Registered: 08/13/09
Loc: California
Thank you, one and all. cool
_________________________
On a Mac since 1984.
Currently: 27" iMacs, Macbook Air, macOS 10.14.x,; iPhones, iPods and iPads galore!

Top
#46884 - 11/17/17 11:39 AM Re: The Name of an Alias [Re: Ira L]
tacit Offline


Registered: 08/03/09
Loc: Portland, Oregon, USA
Originally Posted By: Ira L
Let's say I have a file named "ABC.pdf". I create an alias, which by default is named "ABC.pdf alias".

Questions:
1. If I change the name of the alias to "XYZ.pdf alias" (nothing else has that name), will it still point to ABC.pdf?


Yes.

Originally Posted By: Ira L
2. If I change the name of ABC.pdf to XYZ.pdf and keep the alias as "ABC.pdf alias", will it still point to the newly named XYZ.pdf?


Yes, if XYZ.pdf lives on a Mac-formatted local disk.

Maybe, if XYZ.pdf lives on a file server.

No, if XYZ.pdf lives on a Windows-formatted local disk.

The Mac uses several different techniques to point the alias to the file. It records both a unique ID of the file and also the path to the file. The unique ID of the file relies on the disk being Mac-formatted.

If the disk isn't Mac-formatted, it falls back to the path, Changing the name of the file breaks the path.

If the file lives on a server, it gets complicated, and it depends on a lot of factors, including the server protocol and mount point.
_________________________
Photo gallery, all about me, and more: www.xeromag.com/franklin.html

Top
#46904 - 11/18/17 07:56 AM Re: The Name of an Alias [Re: tacit]
Ira L Offline


Registered: 08/13/09
Loc: California
Originally Posted By: tacit
Originally Posted By: Ira L
2. If I change the name of ABC.pdf to XYZ.pdf and keep the alias as "ABC.pdf alias", will it still point to the newly named XYZ.pdf?


Yes, if XYZ.pdf lives on a Mac-formatted local disk.

Maybe, if XYZ.pdf lives on a file server.

No, if XYZ.pdf lives on a Windows-formatted local disk.


Ahh, this is significant. In real life my original file ABC.pdf resides in Dropbox. So maybe the alias reference will survive, maybe it won't.

For my purposes the sensible thing would be to keep the name of the original document unchanged and only change the name of the alias.

Thanks again.
_________________________
On a Mac since 1984.
Currently: 27" iMacs, Macbook Air, macOS 10.14.x,; iPhones, iPods and iPads galore!

Top
#46932 - 11/19/17 03:42 PM Re: The Name of an Alias [Re: Ira L]
tacit Offline


Registered: 08/03/09
Loc: Portland, Oregon, USA
Keep in mind that files in Dropbox are also on your local disk. For the purpose of this discussion, they count as local files.
_________________________
Photo gallery, all about me, and more: www.xeromag.com/franklin.html

Top
#46943 - 11/20/17 02:24 PM Re: The Name of an Alias [Re: tacit]
joemikeb Offline

Moderator

Registered: 08/04/09
Loc: Fort Worth, Texas
Which brings up the question of aliases to files on the iCloud Drive or when the option to have the Documents and Desktop folders on iCloud is selected? In the case of the Documents folder being on iCloud there may or may not be a copy of the files on the local drive.
_________________________
joemikeb • moderator

Top

Moderator:  alternaut, dkmarsh, joemikeb