"readlink" gets the original path of a symlink; what's the equivalent for Mac aliases?
In the terminal, I can use readlink on a symlink and it prints the target path of the symlink. E.g.
ln -s original.txt symlink.txt
readlink symlink.txt # prints original.txt
How do I do this for Mac alias? I know the path is embedded in the resource fork, because the xattr command will display it in a raw format mixed with other data:
xattr -p -l com.apple.ResourceFork alias_file
However, I don't know enough about this format to extract it. I found the perl Mac::Files man page, but it has no examples, and Google was no help with it.
Maybe there's a way to use osascript to do it, similar to this answer?
Solution 1:
After more googling, I was able to pull together the pieces for an osascript command:
alias_path="your/alias/path"
osascript -e 'tell application "Finder"' -e "posix path of (original item of alias file (posix file \"$alias_path\") as text)" -e 'end tell'