Retrieve the original path from a broken alias

Having a list of aliases, I need to detect which one has a broken target path and I need also to get this path.


I've tested Applescript:


tell application "Finder"

try

set reference_doc to original item of (aliaspath_string as POSIX file as alias)

set originalpath_string to POSIX path of (reference_doc as alias)

on error

return empty

end try

end tell


but applescript is slow, it try always to mount remote servers and don't return the broken path. Any suggestion? Maybe a "do shell script" command line expression?


Thanks


Paul

Macbook Pro, Mac OS X (10.5.4)

Posted on Jun 10, 2014 5:40 AM

Reply
34 replies

Jun 10, 2014 8:07 AM in response to pauclaude

Thanks VikingOSX, I only need a command for a single alias to resolve, as in my script there is already a loop for the list: but I don't know how to implement a bash script into an Applescript script....


Thanks Tony T1, but the problem is the same: I don't know how to add these commands to Applescript, except that using "do shell script", that is for a single line....

Jun 10, 2014 9:13 AM in response to pauclaude

pauclaude wrote:

but I don't know how to implement a bash script into an Applescript script....

I don't know how to add these commands to Applescript, except that using "do shell script", that is for a single line....


You can use multiple lines for a do shell script:

do shell script "

while read -r line

do

/usr/bin/readlink $line

done < ~/alias.lst

exit 0

"

Jun 10, 2014 10:47 AM in response to pauclaude

This is a nice tool, Tony T1, with a simple syntax: you must pass only the alias path.


set theResult to do shell script "/'Users/paolo/Documents/Revolution Files/AliasFixer/aliasPath' '/Users/paolo/Desktop/untitled folder/Smart Scroll'"


Unfortunately, this tool does not accept file paths with strange characters (parentheses, quotes, etc.) and does not allow the shell formating of these characters with escape codes, so it returns many errors

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Retrieve the original path from a broken alias

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.