4

I have a symbolic link from ~/Documents to ~/Dropbox/MyDocuments.

However I noticed that Catalina from time to time deletes my symbolic link and replaces it with a new Documents folder. I think its happening at a reboot but may happen at other times as well. Any way to prevent this

1
  • Are you using iCloud Drive? – Allan Jan 20 '20 at 0:28
5

I have found a workaround for this that I got from the Dropbox forum. As for many years, I 've been syncing my Desktop using Dropbox. However, because of the new layer of security in Catalina, it deletes the folder.

Here is a solution that I did it and it is fine for me now.

After creating the symlink to my Dropbox desktop folder, I locked the link file by displaying its info and checking the 'Locked' checkbox. That seems to do the trick. I checked that I can still write and save to my desktop.

Link: Dropbox Symlinks

1

Locking the symlink as root, as others have mentioned, is the answer. This can all be done from a script so you don't have to enable and log into the root account.

Here is a simple script I wrote that needs to be run as root (with sudo) that takes two arguments:

  1. Short username
  2. Name of your OneDrive folder (Just OneDrive for personal OneDrive accounts)

This script will:

  1. Create a Desktop and Documents folder in the specified OneDrive folder
  2. Copy all items from your existing Desktop and Documents folders into OneDrive using rsync
  3. Delete your Desktop and Documents folders
  4. Symlink Desktop and Documents to OneDrive
  5. Lock the symlinks themselves so they aren't deleted on login/reboot

Warning:

This script doesn't do any error checking or folder existence verification. It might delete all of your files. Make sure you have a backup.

#!/bin/bash

if [[ $# -lt 2 ]] ; then
    echo "Scipt requires two arguments:"
    echo "Argument 1. Short username"
    echo "Argument 2. Name of OneDrive folder"
    exit 1
fi

shortname=$1
onedrive=$2

#########
# DESKTOP
#########

# Make Desktop folder in OneDrive
mkdir -p "/Users/$shortname/$onedrive/Desktop"

# Copy all files from existing Desktop folder to OneDrive Desktop folder
rsync -havux --progress --stats "/Users/$shortname/Desktop" "/Users/$shortname/$onedrive/Desktop"

# Remove existing Desktop folder
rm -rf "/Users/$shortname/Desktop"

# Create symlink to Desktop folder in OneDrive
ln -s "/Users/$shortname/$onedrive/Desktop" "/Users/$shortname/Desktop"

# Set the symlink itself (-h flag) to system locked. (User locked would be uchg)
chflags -h schg "/Users/$shortname/Desktop"

###########
# DOCUMENTS
###########

# Make Documents folder in OneDrive
mkdir -p "/Users/$shortname/$onedrive/Documents"

# Copy all files from existing Documents folder to OneDrive Documents folder
rsync -havux --progress --stats "/Users/$shortname/Documents" "/Users/$shortname/$onedrive/Documents"

# Remove existing Documents folder
rm -rf "/Users/$shortname/Documents"

# Create symlink to Documents folder in OneDrive
ln -s "/Users/$shortname/$onedrive/Documents" "/Users/$shortname/Documents"

# Set the symlink itself (-h flag) to system locked. (User locked would be uchg)
chflags -h schg "/Users/$shortname/Documents"
0

I had a similar issue with the Desktop folder. I would do this :

$ sudo rm -Rf ~/Desktop
$ sudo ln -s ~/Dropbox/Desktop ~/Desktop

And the symlink was replaced by a new folder at the next reboot.


As other users experimented (here and here), it turns out we can not lock a symlink anymore in macOS, the option is greyed out.

I found 2 solutions to this issue :

  • Lock the parent folder (your home folder, /Users/you/) but this will prevent you from adding/deleting files there (source)
  • Disable completely iCloud Drive in System Preferences > Apple ID (Keeping it enabled with "Desktop & Documents Folders" uncheck does not do the trick) enter image description here
0

I have another solution to overcome the problem of greyed locked checkbox:

  1. sudo rm -Rf ~/Desktop
  2. sudo ln -s ~/Dropbox/Desktop ~/Downloads/Desktop
  3. Using the Finder, select ~/Downloads/Desktop icon, select Get info from File menu, and click the Locked checkbox (it is not greyed out!).
  4. Using the Finder, copy ~/Downloads/Desktop icon to ~/ (home) folder.
  5. Delete ~/Downloads/Desktop symlink.

You can use another folder instead of ~/Downloads. And you can do the same to have a Documents symlink pointing to ~/Dropbox/Documents.

You must log in to answer this question.

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