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?
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
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:
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.
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?
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.
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.