1

System specs: 2011 iMac, OS X Mountain Lion 10.8.4

I have come to understand that Rsync does not handle Mac Alises properly, and have now discovered that hundreds of aliases I've previously copied to my portable drive, are dead and useless because of this.

Is there a way to force Rsync to handle aliases? If the answer is a definitive "no", then how can I recursively batch convert all aliases in a directory to symlinks so that they will be handled by Rsync? I've found references to an Applescript that would apparently do this, but the site hosting the script is long dead & gone.

As a last resort, does anyone know of something other than Rsync that would allow for incremental backups and also handle Aliases?

2
  • Instead of including the answer into the question (which may confuse future visitors), please post the solution you found as an answer below.
    – nohillside
    Sep 9 '15 at 14:58
  • 1
    Ah ok, I thought it more likely that someone would read the question for sure and find it, rather than hope they happen to read all the answers and see that one. But sure I'll add it.
    – JVC
    Sep 9 '15 at 15:48
0

Rsync can't look into the content of Alias files which would be needed to convert them. So if you want to have your backup be useable as is (without restoring it to the orignal drive) you will have to replace the Aliases with symlinks.

There is a solution for this on MacOSXHints.com. It needs to be run on your original disk (not on the backup), I would also recommend to test it on some sample directories first.

#!/bin/sh
if [ $# -eq 0 ]; then
    echo "Usage: alias2ln alias1 alias2 alias3..."
    echo "  where alias1, alias2, etc are alias files."
    echo "  Each alias file will be converted into a symlink."
fi

while [ $# -gt 0 ]; do
    if [ -f "$1" -a ! -L "$1" ]; then
        item_name=`basename "$1"`
        item_parent=`dirname "$1"`
        item_parent="`cd \"${item_parent}\" 2>/dev/null && pwd || echo \"${item_parent}\"`"
        item_path="${item_parent}/${item_name}"

        linksource=`osascript<<EOS
tell app "Finder"
set theItem to (POSIX file "${item_path}") as alias
if the kind of theItem is "alias" then
get the posix path of (original item of theItem as text)
end if
end tell
EOS`

        if [ $? -eq 0 ]; then
            if [ ! -z "$linksource" ]; then
                rm "$item_path"
                ln -s "${linksource}" "${item_path}"
                echo "\"${1}\" -> \"${linksource}\""
            fi
        fi
    fi
    shift
done

To run

  • save the code above into a text file (e.g. alias2symlink)
  • execute chmod 755 alias2symlink
  • change to the folder where you want to convert the aliases in
  • execute /path/to/alias2symlink alias1 alias2 ...
8
  • Yeah I found this code previously, but I'm not versed enough in AppleScript to be confident in what it's doing. Running it blindly seemed like a rather high risk activity, but I could create a dummy directory to test on. Will play with it and see how it goes.
    – JVC
    Sep 2 '13 at 15:12
  • BTW, this is the script I referred to in my question, where the owner's site no longer exists. This is apparently a shell script - something I really know only slightly more than nothing about - and I was hoping to find the AppleScript version he mentions, but I've had no success in that department. =(
    – JVC
    Sep 2 '13 at 15:15
  • I looked up how to run a shell script, but it doesn't seem to work no matter what I try. All I get is -bash: alias2ln.txt: command not found. What am I doing wrong?
    – JVC
    Sep 2 '13 at 15:36
  • Amended the answer. The AppleScript is actually included in the script above and just needed to read the target of the Alias.
    – nohillside
    Sep 2 '13 at 15:44
  • I'm afraid I don't see anything that wasn't there when I last viewed your answer. I can't figure out how to execute this script. And the AppleScript contained within it, only appears to identify if the item is an alias, and get the path of the original item. It doesn't actually do the conversion. Is there an AppleScript-only solution for this?
    – JVC
    Sep 2 '13 at 16:16
-1

For future reference I found a simple Mac service that converts aliases to symlinks perfectly!

That solution actually wraps the script mentioned in the other answer as an automator action to make it easier to use by those unfamiliar with Terminal.

To re-create the service, use Automator to create a service that receives selected files and folders, select the Run shell script action, and paste pastix's script into the script area.

1
  • you might wish to summarize the solution and perhaps even post the script for future users searching for this answer. the original may disappear.
    – cmason
    Sep 9 '15 at 16:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .