Sunday, April 18, 2021

#1 2021-02-25 10:34:48 am

Kuulest
Member
Registered: 2021-01-14
Posts: 5

do aliases still work?

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

Applescript:


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


Filed under: alias

Offline

 

#2 2021-02-25 12:06:09 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4621

Re: do aliases still work?

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

Applescript:

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:

Applescript:

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

Offline

 

#3 2021-02-25 04:12:43 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6615

Re: do aliases still work?

Kuulest wrote:

Do aliases still work in Mojave as they did in Leopard?



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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#4 2021-02-25 04:35:15 pm

Kuulest
Member
Registered: 2021-01-14
Posts: 5

Re: do aliases still work?

Shane Stanley wrote:

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

Last edited by Kuulest (2021-02-25 04:39:12 pm)


Filed under: alias

Offline

 

#5 2021-02-25 05:27:39 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6615

Re: do aliases still work?

Kuulest wrote:

I tried my original script on ElCapitan and it works...



El Capitan did not use APFS format drives.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#6 2021-02-26 12:39:53 am

Kuulest
Member
Registered: 2021-01-14
Posts: 5

Re: do aliases still work?

Yes, I know. smile  Therefore I've tested on ElCapitan and it worked.

Offline

 

#7 2021-02-26 01:10:00 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4621

Re: do aliases still work?

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

Offline

 

#8 2021-02-26 02:52:27 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 671

Re: do aliases still work?

To add to Shanes post:

Any upgrade or install to Mojave convert HFS+ to APFS filesystem. And the only way to get future
Software Update the boot drive need to be AFPS. So would it be possible to have Mojave on HFS+, answer is yes with Carbon Copy Cloner.

Its a reason why any macOS beyond High Sierra should be installed on SSD.

Last edited by Fredrik71 (2021-02-26 10:58:54 am)


if you are the expert, who will you call if its not your imagination.

Offline

 

#9 2021-02-26 03:13:30 am

Kuulest
Member
Registered: 2021-01-14
Posts: 5

Re: do aliases still work?

Yvan Koenig wrote:

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:

tell application "Finder"
    set folderName to (desktop as text)
    set thisAliasStaysForever to (folderName & fileName) as alias
-- you can tinker in the properties as you like as long you don't change the name property
    set extension hidden of thisAliasStaysForever to false  -- just for example
        set name of thisAliasStaysForever to "somethingDifferent"
-- the following doesn't work any longer with APFS but on Mac OS Extended
        doSomethingWith(thisAliasStaysForever)
end tell



Browser: Safari 605.1.15
Operating System: macOS 10.14

Last edited by Kuulest (2021-02-26 03:19:19 am)


Filed under: alias

Offline

 

#10 2021-02-26 05:37:49 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4621

Re: do aliases still work?

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

Offline

 

#11 2021-02-26 06:07:40 am

Kuulest
Member
Registered: 2021-01-14
Posts: 5

Re: do aliases still work?

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

Offline

 

#12 2021-02-26 08:18:20 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4621

Re: do aliases still work?

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

Offline

 

#13 2021-02-26 08:50:20 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 839

Re: do aliases still work?

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


2018 Mac mini - macOS Catalina

Offline

 

#14 2021-02-26 04:41:50 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6615

Re: do aliases still work?

peavine wrote:

distinguishing between an alias and an alias file



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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)