Under Windows, the process of redirecting a user profiles home folders aka ‘special folders’ or ‘known folders’ such as Documents, Desktop, Photos and Movies can be achieved through Group Policy or via the GUI. Newer versions of the Windows OneDrive client also include an automated facility to redirect Desktop, Documents and Pictures – but only under Windows. macOS does not offer any automatic method for this. This article discusses how to redirect home folders to OneDrive, OneDrive for Business, Dropbox, Google Drive or other cloud services under macOS.
Why redirect?
The main reason you would want to consider implementing redirects in your environment is for convenience. On company issued machines, end users do not want – and will never properly use – a cloud service that requires additional manual steps to store data in a special cloud folder. Operating Systems are designed to push users to save their data in their ‘Documents’ folder, not into ‘~/OneDrive – My Organisation/Some Folder’. No effort on the part of the end user, should mean greater likelihood of data safeguarding and an easier selling point for IT.
For the administrator. The desire for minimal contact is paramount. Issuing complex end-user instructions for the end user to enable Google Drive Backup and Sync on certain folders will likely reduce compliance while increasing contact and support time for IT. If you can administratively automate using a controllable standard, the quality of IT service will increase.
Do you need to redirect?
Whether you need to actually redirect the data to the cloud service that you use may depend on you needs. Google Drive’s Backup and Sync app has an settings option to cloud sync any folder to your Drive account. This can be used to negate the need to redirect the home folders in a manual, but less technical fashion.
Such an option is not available for OneDrive users, despite year of users requesting the feature be added to the macOS client, to date, Microsoft have not implemented either an automatic redirect or a manual folder sync features.
View: How can we improve OneDrive on Mac? KFM Known Folder Move on Mac
Performing the redirect
The process to individually redirect your home folders to a cloud service requires four steps
- Install the client and sign the user into their cloud storage account
- Move the data to the desired location in the cloud storage’s local cache to begin cloud synchronisation
- Create a symlink from the original location to the redirected location
- Restore Finder shortcuts (if applicable)
Step 1 is beyond the intended scope of this article as different options exist for deploying and automating the configuration of the various cloud clients that are on the market.
Example: Moving the macOS Home Folders to OneDrive for Business
The following script will move current home folder locations to the cloud and establish new symlinks in the macOS profile folder for each.
The script provides redirects for
- Documents
- Desktop
- Downloads
- Pictures
- Movies
- Music
The folder remapping will look like:
Original Path: /Users/Joe Bloggs/Documents
New Path: /Users/Joe Bloggs/OneDrive - My Company Ltd/Documents
#!/bin/bash # Current User Local Home Folders to OneDrive # Note: Do NOT run as su, just sudo sudo ODFolder="OneDrive" ODOrganisation="My Company Ltd" ODFinalFolder="$ODFolder - $ODOrganisation" # Documents WorkingFolder="Documents" sudo mv -f ~/$WorkingFolder "/Users/$USER/$ODFinalFolder" ln -s "/Users/$USER/$ODFinalFolder/$WorkingFolder" ~/$WorkingFolder # Desktop WorkingFolder="Desktop" sudo mv -f ~/$WorkingFolder "/Users/$USER/$ODFinalFolder" ln -s "/Users/$USER/$ODFinalFolder/$WorkingFolder" ~/$WorkingFolder # Downloads WorkingFolder="Downloads" sudo mv -f ~/$WorkingFolder "/Users/$USER/$ODFinalFolder" ln -s "/Users/$USER/$ODFinalFolder/$WorkingFolder" ~/$WorkingFolder # Pictures WorkingFolder="Pictures" sudo mv -f ~/$WorkingFolder "/Users/$USER/$ODFinalFolder" ln -s "/Users/$USER/$ODFinalFolder/$WorkingFolder" ~/$WorkingFolder # Movies WorkingFolder="Movies" sudo mv -f ~/$WorkingFolder "/Users/$USER/$ODFinalFolder" ln -s "/Users/$USER/$ODFinalFolder/$WorkingFolder" ~/$WorkingFolder # Music WorkingFolder="Music" sudo mv -f ~/$WorkingFolder "/Users/$USER/$ODFinalFolder" ln -s "/Users/$USER/$ODFinalFolder/$WorkingFolder" ~/$WorkingFolder
The script should be saved to a shell script file and executed from Terminal e.g.
chmod +x OneDrive-User-Migration.sh .\OneDrive-User-Migration.sh
If you run it manually, elevate to sudo before running the rest of the script.
Once executed correctly with elevation, the script will move the individual home folders into the cloud storage root and perform a re-link back to where macOS expects to find them.
There are two negative consequences associated with performing the home folder redirect
Firstly, existing Finder shortcuts “favourites” to the home folders will be deleted during the move operation
You will need to restore these as part of your scripting using
sfltool add-item com.apple.LSSharedFileList.FavouriteItems file://path/to/target
on macOS versions up to 10.12 or using a third party tool such as mysides on newer versions
View: mysides
Secondly, when you do restore the favourite shortcuts, they will lose their normal macOS shell folder icons and be replaced with normal folder icons
Example: Reversing the redirection
Should you wish to reverse the redirection as part of testing or a change in cloud provider. You can use the following script to restore data from the cloud account to their original paths in the local file system.
#!/bin/bash # Current User OneDrive to Local Home Folders # Do NOT run as su, just sudo sudo ODFolder="OneDrive" ODOrganisation="My Company Ltd" ODFinalFolder="$ODFolder - $ODOrganisation" # Documents WorkingFolder="Documents" if [[ -L "/Users/$USER/$WorkingFolder" && -d "/Users/$USER/$WorkingFolder" ]] then unlink "/Users/$USER/$WorkingFolder" fi sudo mv -f "/Users/$USER/$ODFinalFolder/$WorkingFolder" /Users/$USER # Desktop WorkingFolder="Desktop" if [[ -L "/Users/$USER/$WorkingFolder" && -d "/Users/$USER/$WorkingFolder" ]] then unlink "/Users/$USER/$WorkingFolder" fi sudo mv -f "/Users/$USER/$ODFinalFolder/$WorkingFolder" /Users/$USER # Downloads WorkingFolder="Downloads" if [[ -L "/Users/$USER/$WorkingFolder" && -d "/Users/$USER/$WorkingFolder" ]] then unlink "/Users/$USER/$WorkingFolder" fi sudo mv -f "/Users/$USER/$ODFinalFolder/$WorkingFolder" /Users/$USER # Pictures WorkingFolder="Pictures" if [[ -L "/Users/$USER/$WorkingFolder" && -d "/Users/$USER/$WorkingFolder" ]] then unlink "/Users/$USER/$WorkingFolder" fi sudo mv -f "/Users/$USER/$ODFinalFolder/$WorkingFolder" /Users/$USER # Movies WorkingFolder="Movies" if [[ -L "/Users/$USER/$WorkingFolder" && -d "/Users/$USER/$WorkingFolder" ]] then unlink "/Users/$USER/$WorkingFolder" fi sudo mv -f "/Users/$USER/$ODFinalFolder/$WorkingFolder" /Users/$USER # Music WorkingFolder="Music" if [[ -L "/Users/$USER/$WorkingFolder" && -d "/Users/$USER/$WorkingFolder" ]] then unlink "/Users/$USER/$WorkingFolder" fi sudo mv -f "/Users/$USER/$ODFinalFolder/$WorkingFolder" /Users/$USER