How to sync OS X desktop to Dropbox?

8,870

Solution 1

Using Folder Actions

This will – whenever you add a new file – synchronize your Desktop with a Dropbox folder of your choice. First, create the Dropbox folder where you want your desktop files to stay, e.g. ~/Dropbox/Desktop.

Then, open up Automator.app and create a new Folder Action. On the top, select your real Desktop.

enter image description here

To the Automator action, add a Run Shell Script action from the left pane. Paste the following.

rsync -rta --delete ~/Desktop/ ~/Dropbox/Desktop/

enter image description here

Save the action.

enter image description here

Now, this will run by default, and whenever an item is added to your Desktop, it will be mirrored with the Dropbox. If you delete an item from your Desktop, there will be no changes, so you have to add something (e.g. create a new folder and delete it right away) to force a sync.

If you ever want to disable it, right-click your Desktop icon from Finder, and select Services » Folder Action Setup. Here, uncheck your Desktop.

enter image description here


Copying with cron

A very static, non-preferred way involves setting up cron. If you just want to copy the items, you can open your Terminal, and enter:

mkdir -p ~/Dropbox/Desktop
crontab -e

Then, paste the following, and save:

0   12  *   *   *   rsync -rt --delete ~/Desktop/ ~/Dropbox/Desktop/

This will make a backup every day, at 12:00. You can change the 12 to * to do this every hour. To disable it again, enter crontab -e and delete this line, then save.

Solution 2

I prefer the symlink method, but when setting up additional Mac's to share the sync, it can get tricky.

First, I have a folder in Dropbox dedicated to "osx sync" ... e.g.: sync_osx

  • Before I setup the symlink on the new Mac, I temporary "move" the Desktop folder out of the sync_osx (but still inside the main DropBox folder).

  • I then open Terminal and type:

    cd ~/Dropbox/sync_osx

    ln -s ~/Desktop/ Desktop

  • Finally, I move the files back into the newly created Desktop folder in ~/Dropbox/sync_osx/Desktop.

By moving the files within the Dropbox folder, Dropbox quickly syncs and file change history remains intact.

Solution 3

Since you want the content from your Desktop in Dropbox, I recommend first moving the content on your Desktop to Dropbox. You can put your Desktop anywhere in Dropbox, but I recommend directly as Dropbox/Desktop. I'll assume for now that you have Dropbox installed as ~/Dropbox and your Desktop as ~/Desktop. So to move the files:

# ensure the directory exists on Dropbox
mkdir -p ~/Dropbox/Desktop

# move local files to the Dropbox-hosted Desktop
mv ~/Desktop/* ~/Dropbox

Next, you want to create a symlink so that ~/Desktop redirects to ~/Dropbox/Desktop. However, you can't do that while there's an existing Folder at ~/Desktop, so you'll want to remove it.

Before you do that, though, you'll probably want to retain the Folder icon for the Desktop. The only way I know to do that is to copy it to the clipboard using Finder. Open Finder and navigate to your home directory, select the Desktop, and then Get Info on it (⌘I). Select the folder icon in the upper left and copy it to the clipboard (⌘C). Next, restore the icon for the Desktop folder by navigating to your Dropbox/Desktop folder in Finder, invoking Get Info on it, selecting the icon in the upper right, and pasting the icon that you copied earlier (⌘V).

Now you're ready to remove the old Desktop folder.

# remove ~/Desktop
sudo rm -Rf ~/Desktop

sudo is required to remove that folder because it is system-managed.

Then, create the symbolic link so that the Desktop is available from both locations:

ln -s Dropbox/Desktop ~/Desktop

The above technique should work on the first machine, but also subsequent machines, even if the new machines already have content on the Desktop (which gets merged with the cloud-hosted copy). It saves storage and minimizes synchronicity issues by only keeping one copy of the content on the disk.

Finally, I've observed that this technique causes the Desktop to be lost from the Sidebar / Favorites. Restore the shortcut in the Favorites by navigating in Finder to the Dropbox and dragging the Desktop to the Sidebar. Note that the icon for the Desktop in the Sidebar will be replaced by a generic Folder icon. I do not yet know a way to restore that icon (and it may not be possible).

I welcome any suggestions on improving this technique - specifically how to invoke all the actions through the command line or retaining the icon in the Sidebar.

This technique seems to work for other special folders too (Downloads, Documents, etc).

Share:
8,870

Related videos on Youtube

epsilon8
Author by

epsilon8

Updated on September 18, 2022

Comments

  • epsilon8
    epsilon8 almost 2 years

    How can I sync all my Desktop files to Dropbox, so that my desktop still feels, looks and works like a normal Desktop?

  • user72923
    user72923 almost 12 years
    Your symlink params are backwards: ln -s ~/Dropbox/Desktop ~/Desktop
  • Anthony
    Anthony over 9 years
    +1 Symlinks all the way for "true" transparency.
  • Jason R. Coombs
    Jason R. Coombs about 9 years
    -1 This answer contains three separate answers and should have been submitted as such. The symlink technique doesn't work, but instead creates a ~/Desktop/Desktop folder that is synced, but still fails to sync other content in ~/Desktop.
  • Jason R. Coombs
    Jason R. Coombs about 9 years
    This answer could be improved by clarifying that it's a different way of using symlinks. It's keeping the ~/Desktop folder as authoritative and linking from the Dropbox-hosted folder. I don't like this technique because it relies on Dropbox being aware of and supporting that model (something which it explicitly doesn't support on Windows). Additionally, why go to all that trouble rather than linking ~/Desktop to ~/Dropbox/sync_osx/Desktop?
  • slhck
    slhck about 9 years
    @JasonR.Coombs We actually prefer users to submit one answer if possible. I removed the symlink part. If you have a better symlink solution I'd appreciate if you could post that.
  • Jason R. Coombs
    Jason R. Coombs about 9 years
    Thanks @slhck. I've changed my vote on this answer. I have drafted another answer based on symlinks, but I'm not yet happy with it. I hope to publish it in the future.
  • besson3c
    besson3c about 8 years
    +1. Dunno why this answer's not getting any love. I prefer this to the other approaches: symlinking from Desktop to Dropbox means it's opt-in on a per-machine basis. Symlinking from Dropbox to Desktop looks like it'll push on any machine that Dropbox is installed on.
  • besson3c
    besson3c about 8 years
    Here's a bash script I wrote to set up Desktop syncing using your approach. gist.github.com/apjanke/98a3374177de2b61bec1494a29474266. I've used it on a handful of OS X 10.9 and 10.11 machines. Seems to work fine. It doesn't handle folder icons. Looks like Rez/Derez can do that, for someone with more time and motivation.