Has an Alias to a file been dropped ?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Has an Alias to a file been dropped ?

Post by Simon Knight » Mon Mar 28, 2022 4:06 pm

Hi Stam,

Thanks for trying. Unfortunately the command does not work when the alias and the target are on different volumes. There is no mention of alias in the result :
com.adobe.raw-image
which I guess means it is a different kind of "link". This is back to the start as the Livecode and the Applescript functions have the same issue : when asked the "alias" reports its kind as that of the target so therefore there is no alias. Whats annoying is that MacOS displays the details when a command I is made on the "alias".
2022-03-28-155403-Screenshot 2022-03-28 at 15.53.57.png
Screen shot of file information.
This is from an alias that points to a target on second mounted volume as can be seen in the "Where" and "Original" fields above. The challenge is discovering how MacOS sees the "Kind" as alias and resolves the path to the target file. Probably worth mentioning that the Livecode command

Code: Select all

If tFileName is a File
returns true which is not helpful.
best wishes
Skids

stam
Posts: 2673
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Has an Alias to a file been dropped ?

Post by stam » Mon Mar 28, 2022 4:25 pm

Ok now i'm confused. Not sure i understand what the volume on which the referenced file resides has anything to do with the mdls command?
This does not examine the validity of the symlink or alias but instead looks at the metadata of the alias file.

Code: Select all

mdls -raw -name kMDItemContentType <filename>
returns

Code: Select all

com.apple.alias-file% 
on aliases created on macOS regardless for me anyway.

I tested this both on files that i deleted (ie invalid alias pointing to a non-existent file) as well as aliases that point to a file on a USB drive.

can you share your alias file?

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Has an Alias to a file been dropped ?

Post by Simon Knight » Mon Mar 28, 2022 4:50 pm

Glad I'm not the only one who is confused. The object is displayed in finder as an alias and is stored on the main drive, the target or true file is stored on a removable solid state drive which is mounted.
2022-03-28-164341-Screenshot 2022-03-28 at 16.43.35.png
Running MDLS returns :
Simons-MacBook-Pro:~ skids$ mdls -raw -name kMDItemContentType /Users/skids/Pictures/SophieBoleAlias/2018-11-11-164049-1150584-Flash-Model-shoot-Sophie-Bole-portrait-Night-Club-NightClub-Lincoln-.RW2
com.panasonic.rw2-raw-imageSimons-MacBook-Pro:~ skids$
So it seems that MDLS is following the symbolic link to get the details.

I have tried to attach the link object but am unable because the operation resolves the link and provides the target / true file or if using the Add Files option the objects are greyed out.


S
2022-03-28-164341-Screenshot 2022-03-28 at 16.43.35.png
Attachments
2022-03-28-164910-Screenshot 2022-03-28 at 16.49.05.png
best wishes
Skids

stam
Posts: 2673
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Has an Alias to a file been dropped ?

Post by stam » Mon Mar 28, 2022 5:03 pm

zip it lol...

here's an alias from me:
LiveCode 10.0.0 (dp 3).zip
(1014 Bytes) Downloaded 65 times
If you want, send a source file as well as it's alias so that it's possible to replicate what you have... but even just the alias would be interesting to look at.

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Has an Alias to a file been dropped ?

Post by Simon Knight » Mon Mar 28, 2022 5:39 pm

zip attached, the original is to large so here is a link to a copy in my drop box

https://www.dropbox.com/s/6jue0ac99ql1z ... -.RW2?dl=0
Attachments
2018-11-11-164049-1150584-Flash-Model-shoot-Sophie-Bole-portrait-Night-Club-NightClub-Lincoln-.RW2.zip
(513 Bytes) Downloaded 57 times
best wishes
Skids

stam
Posts: 2673
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Has an Alias to a file been dropped ?

Post by stam » Mon Mar 28, 2022 11:58 pm

Thanks for posting those Simon,

indeed your aliases are a problematic because they're symlinks (I think!), not macOS aliases.
If i create an alias to the source file in macOS that works fine.

a bit of googling suggests that ls -l is the command to use, as you suggested
Running this on your symlink returns

Code: Select all

lrwxr-xr-x  1 stam  staff  155 28 Mar 21:10 /Users/stam/Desktop/2018-11-11-164049-1150584-Flash-Model-shoot-Sophie-Bole-portrait-Night-Club-NightClub-Lincoln-.RW2 -> /Volumes/Image_Library_SSD/Photo-Library/2018/2018-11-11/2018-11-11-164049-1150584-Flash-Model-shoot-Sophie-Bole-portrait-Night-Club-NightClub-Lincoln-.RW2
so the location of the symlink is resolved and the referenced file is hardcoded into it.
Apparently the 'l' in the permissions (lrwxr-xr-x) signifies it's a symlink, but doesn't apply to aliases.

So i guess you'd need to iterate first doing an ls -l on the file, if no 'l' in the permissions then do the mdls command as above to rule it out being an alias. Not sure if any of this is of any help...

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Has an Alias to a file been dropped ?

Post by Simon Knight » Tue Mar 29, 2022 11:44 am

Thanks for your help, I have put the following together and it appears to work when either files, aliases or symlinks are dropped .

Code: Select all

on dragDrop
   ## MAC ONLY!!!!
   set the cursor to busy
   put the dragdata["Files"] into tFiles  -- also tried "text"

   repeat for each line tFile in tFiles
      put "ls -l " & tFile into tCommand
      put shell(tCommand) into tShellResult
 
      if char 1 of tShellResult is "l" then
         --symbolic link needs resolving
         put the last word of tShellResult into tFileSpec
      else
         -- Might be true file or a Finder Alias
         put "mdls -name kMDItemKind" && tFile  into tCommand
         put shell(tCommand) & cr into tShellResult
         if the last word of tShellResult is (quote & "Alias" & quote) then
            put aliasreference(tFile) into tFileSpec
         else
            put tFile into tFileSpec
         end if
      end if
      put "File reference resolves to :" && tFileSpec & cr after field "debug"
   end repeat
   pass dragdrop
end dragDrop
Quite hard work for something that should be simple.
S
best wishes
Skids

stam
Posts: 2673
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Has an Alias to a file been dropped ?

Post by stam » Tue Mar 29, 2022 11:55 am

Simon Knight wrote:
Tue Mar 29, 2022 11:44 am
Thanks for your help, I have put the following together and it appears to work when either files, aliases or symlinks are dropped .

Code: Select all

on dragDrop
   ## MAC ONLY!!!!
   set the cursor to busy
   put the dragdata["Files"] into tFiles  -- also tried "text"

   repeat for each line tFile in tFiles
      put "ls -l " & tFile into tCommand
      put shell(tCommand) into tShellResult
 
      if char 1 of tShellResult is "l" then
         --symbolic link needs resolving
         put the last word of tShellResult into tFileSpec
      else
         -- Might be true file or a Finder Alias
         put "mdls -name kMDItemKind" && tFile  into tCommand
         put shell(tCommand) & cr into tShellResult
         if the last word of tShellResult is (quote & "Alias" & quote) then
            put aliasreference(tFile) into tFileSpec
         else
            put tFile into tFileSpec
         end if
      end if
      put "File reference resolves to :" && tFileSpec & cr after field "debug"
   end repeat
   pass dragdrop
end dragDrop
Quite hard work for something that should be simple.
S
Very nicely done Simon!
You are right, that was an inordinate amount of work for a simple function.

Maybe make that a feature request?
A nice function could return an list or array where the first item/element is boolean for isAlias or some such, the 2nd is the file path to the alias and the 3rd is the referenced file.

And can probably be made cross-platform as well as i think all windows shortcuts have the extension .lnk, so probably quite easy to add that although i suspect you'd need to read the binary data of the shortcut file to get the referenced file/folder path...

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Has an Alias to a file been dropped ?

Post by Simon Knight » Tue Mar 29, 2022 1:47 pm

I'm planning on waiting to see what the bug report generates as the dictionary claims that the command AliasReference should work with symlinks :
Returns the name and location of the file or folder that an alias, symbolic link, or shortcut refers to.
Another option would be to write a widget to replace the handler but perhaps the handler is the simplest if it is fast enough.

S
best wishes
Skids

Post Reply

Return to “Talking LiveCode”