Page 2 of 2
Re: Has an Alias to a file been dropped ?
Posted: Mon Mar 28, 2022 4:06 pm
by Simon Knight
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 (65.4 KiB) Viewed 2762 times 2022-03-28-155403-Screenshot 2022-03-28 at 15.53.57.png](./download/file.php?id=17069&t=1&sid=c766011838f97437706f9e3f3de53d35)
- 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
returns true which is not helpful.
Re: Has an Alias to a file been dropped ?
Posted: Mon Mar 28, 2022 4:25 pm
by stam
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
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?
Re: Has an Alias to a file been dropped ?
Posted: Mon Mar 28, 2022 4:50 pm
by Simon Knight
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.
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
Re: Has an Alias to a file been dropped ?
Posted: Mon Mar 28, 2022 5:03 pm
by stam
zip it lol...
here's an alias from me:
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.
Re: Has an Alias to a file been dropped ?
Posted: Mon Mar 28, 2022 5:39 pm
by Simon Knight
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
Re: Has an Alias to a file been dropped ?
Posted: Mon Mar 28, 2022 11:58 pm
by stam
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...
Re: Has an Alias to a file been dropped ?
Posted: Tue Mar 29, 2022 11:44 am
by Simon Knight
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
Re: Has an Alias to a file been dropped ?
Posted: Tue Mar 29, 2022 11:55 am
by stam
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...
Re: Has an Alias to a file been dropped ?
Posted: Tue Mar 29, 2022 1:47 pm
by Simon Knight
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