do aliases still work?

I tried the following example from a very old (but very good) book from Stephen Kochan.


tell application "Finder"	
	-- define an alias
	set testFile to ("Mojave:Users:martin:desktop:someFile") as alias
	-- rename the name property
	set name of testFile to "newFileName"
	-- try to access the alias
	get size of (info for testFile) -- alias not found
end tell

Do aliases still work in Mojave as they did in Leopard? Is there a workaround?

thanks in advance, Martin

Browser: Safari 605.1.15
Operating System: macOS 10.14

As far as I know, it’s not a new feature.
The same behavior is got under 10.13.6.

set p2d to path to desktop as string
tell application "Finder"
	-- define an alias
	set testFile to (p2d & "someFile") as alias
	log testFile --> (*alias SSD 1000:Users:**********:Desktop:someFile:*)
	-- rename the name property
	set name of testFile to "newFileName"
	log testFile --> (*alias /Users/**********/Desktop/someFile*)
end tell

As you may check, after the renaming, the alias no longer point to an HFS path but the name of the pointed item is not modified.

Below is an edited version which works:

set p2d to path to desktop as string
tell application "Finder"
	-- define an alias
	set testFile to (p2d & "someFile") as alias
	log testFile --> (*alias SSD 1000:Users:**********:Desktop:someFile*)
	
	-- rename the name property
	set newName to "newFileName"
	set name of testFile to newName
	log testFile --> (*alias /Users/**********/Desktop/someFile*)
	set testFile to (p2d & newName) as alias
	log testFile --> (*alias SSD 1000:Users:**********:Desktop:newFileName*)
	size of testFile --> 66463
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 25 février 2021 19:05:50

It’s not directly an OS change – they just don’t work on APFS format disks.

I tried my original script on ElCapitan and it works…
Though that’s no solution for Mojave, but thank you nevertheless

El Capitan did not use APFS format drives.

Yes, I know. :slight_smile: Therefore I’ve tested on ElCapitan and it worked.

My boot volume, an external SSD, is an APFS device.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 26 février 2021 08:09:49

Your script doesn’t meet my problem. You defined a new alias for the renamed file and of course you can access the properties with the new alias. My script was intended to do the following:

Browser: Safari 605.1.15
Operating System: macOS 10.14

I tried to show you that renaming an alias is no longer reflected in the variable storing the alias when the hosting device is an APFS one.
As I wrote, in such case, renaming an alias changes the content of the variable whose HFS path is replaced by a POSIX path which doesn’t reflect the new name.
This is why I urged you to build the new pathname by yourself.
For me it’s not a problem because, for years I no longer use the dinosaur named “Finder” for such tasks.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 26 février 2021 12:37:21

now I understand your intention. Though it doesn’t make sense to me, to create a new alias after the name has been changed. This contradicts the reason for using aliases. I just worked through Kochans book and was stuck with this issue, so I had to ask.

Which alternative to Finder do you use? Is it scriptable?

Operating System: macOS 10.14

I use System Events or ASObjC.
Finder is triggered only when I need to manipulate windows which I does rarely.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 26 février 2021 15:18:13

This isn’t the issue raised by the OP, but it might be worth distinguishing between an alias and an alias file. An alias file works as expected with recent versions of macOS and will continue to point to the original file even if that file is renamed.

Also, while on the topic of aliases not working as expected, it might be noted that aliases often do not work with System Events if macOS Catalina is being used. I don’t know if this has been fixed in Big Sur.

https://macscripter.net/viewtopic.php?pid=199777

Initially, they were much the same thing – that’s why they were called aliases in scripting. They were both handled by pre-OS X code known as alias manager. Alias files were changed at one point to use the more modern bookmark format, and AppleScript is the only thing still using the alias manager. So it’s no surprise the alias manager wasn’t updated for APFS.