macos tips & tricks

How to prevent elements in iCloud Drive from syncing with your Macs

A quick and easy workaround without any additional software.

iCloud Drive automatically downloads everything to all connected desktop and laptop devices. Nice – to use with the free 5GB. Currently iCloud storage plans go up to 2TB so unless you have too much space on all your devices you might want to be a bit selective with what each of them is syncing.

Luckily, there is a quick and easy workaround that does not involve any additional software, just a little help from Automator and a single line of shell script.

Solution 1

To prevent a folder or a file in iCloud Drive from downloading to your laptop or desktop Mac all you need to do is:

  1. Open Automator and create a new document Folder Action
  2. Choose a folder in your iCloud Drive (FOLDER_TO_EXCLUDE_FROM_SYNC)
  3. From Actions menu choose ‘Run Shell Script’ and add it to your workflow
  4. In the Shell Script window add the following line:
    brctl evict /Users/YOUR_USERNAME/Library/Mobile\ Documents/com\~apple\~CloudDocs/FOLDER_TO_EXCLUDE_FROM_SYNC


Screenshot of Automator window

Optionally you can also include a wildcard sign (* or **)  after your directory:
brctl evict /Users/YOUR_USERNAME/Library/Mobile\ Documents/com\~apple\~CloudDocs/FOLDER_TO_EXCLUDE_FROM_SYNC/*
brctl evict /Users/YOUR_USERNAME/Library/Mobile\ Documents/com\~apple\~CloudDocs/FOLDER_TO_EXCLUDE_FROM_SYNC/**

If you only need to evict a single file, set-up the folder action the same way and change the path in the shell script to point to your file rather than folder, the file must be inside that folder.


The Optimise Mac Storage option must be enabled.


And that’s it! Save your script and try adding something to the folder using another device synced with the same iCloud Drive and see if it works.

You will be able to see the files and directories in the iCloud Drive folder that you’ve just blocked from syncing but they won’t download to your Mac saving you on precious (and pricey ;-) storage.

Note: The above example could be potentially applied to a Desktop and Documents folders should you have them synced with the iCloud Drive.

Solution 1a

Same idea as the Solution 1, but using the Launch Daemon rather than Automator to run the script. The below snippet is better for folders that contain many elements (e. g. htdocs folder :-) as it recurses all directories, but might be using more energy. (important on a MacBook).

find "/Users/YOUR_USERNAME/Library/Mobile Documents/com~apple~CloudDocs/FOLDER_TO_EXCLUDE_FROM_SYNC" -name "*" -type d -depth -exec brctl evict {} \;

Will post the lunchd code soon ;-)

I’m currently considering the change of the lunchd’s WatchFolder with a command line program fswatch. Unlike the WachFolder, fswatch returns the filesystem event that can then be send to the evict script rather than recursing over all elements each time something is being updated.


How to get full path of a folder on Mac:

  1. Open Terminal App
  2. Drag a folder to the Terminal window
  3. Select, copy, paste

Leave a Reply