Dropbox ignore — solving ignoring node_modules and other folders from syncing (on a mac)

Boz Bundalo
7 min readMay 22, 2020

--

The Problem

I’ve written in 2018 about this problem and the pain it was to use Dropbox to keep your files and development sync-ed between multiple computers while using Dropbox to keep the files in the cloud. The main issue was the amount of files that needed to be synced for common folders like node_modules (npm) and vendor (composer) that would take forever as these folders might have dependencies of dependencies and they can contain 10s of thousands of files. You can read the “dirty” approach to this problem in my previous post here (Solving painful syncing of node_modules when using Dropbox or Google Drive).

Flaws of Previous Solution

My solution has served me pretty well for a couple of years and it wasn’t without flaws however. Positives were that it was working with any cloud syncing service such as Dropbox or Google Drive as it was relying on GoodSync software (some people used rSync to achieve similar goal), but on the other hand one of the flaws in my approach, aside from duplicating the files, was that some node_module and vendor folders were ignored even though they shouldn’t have been, leading to somewhat problematic ‘rebuild’ process on the new computer via npm or composer as any vendor or node_modules folders would be excluded in your project.

You can see that this can be annoying, hunting down the places where I needed to run composer and npm again to generate the files that were excluded from sync. Even though it wasn’t a massive problem as I would do this only once on the target machine, it was still annoying.

The Now —Dropbox Added Ignore

Well, two years have passed and Dropbox finally introduced an ignore feature on folders and files via setting file and folder attributes xattr making me rethink my approach to a much more git-like way of ignoring folders I don’t want sync-ed.

You can read about the ignore feature here How to set a Dropbox file to be ignored. Basically, you find the located the file/s or folder/s you want to ignore from syncing and run the command:

xattr -w com.dropbox.ignored 1 filename/folder

To revert to normal syncing you would run this command:

attr -r com.dropbox.ignored filename/folder

The feature works on Mac, Windows and Linux but the purpose of this guide is not to just highlight the feature but to show how I automated my workflow on OSX.

The way it works is that if you ignore the file/s or folder/s when you set the flag Dropbox will ignore it completely from syncing. If you un-ignore it, it will treat normally as any other folder/file.

The good part is that the attribute you set can be set outside the Dropbox folder and when the file/folder is moved to Dropbox folder the app will sync and see the attribute and will put a small (ignored icon right next to it — see image). If you set the flag on a file/folder inside the dropbox folder that’s actively sync-ed, it will remove it from the cloud (as if you deleted it).

Dropbox shows you when the file/folder is ignored

If you un-ignore it, it will behave like you just copied the folder and will sync normally (see image)

If you remove ignore it will act as normal sync

You can do this action on files and folders and it really behaves similarly to .gitignore.

This is all nice and awesome, but I really found it tiresome to constantly type commands when I needed to quickly manage my folders and files I wanted ignored in my projects. So I’m about to outline my workflow that works amazingly well now for me and no more duplicating files (like i had in my GoodSync/Dropbox solution)

Enter, OSX Automator! Simple, elegant and it’s as easy as Sunday morning ;)

If you are a seasoned developer and OSX user you are already familiar with it but for those who have not used it much it’s a powerful OSX utility that allows you to script operations, build repetitive workflow actions in OSX and run them in myriad of ways (make an application out of it, a service and similar). It’s really a powerful tool.

So in essence, I created 2 simple actions (Dropbox Ignore and Dropbox Unignore) and assigned script (to run terminal command I outlined above) so I can see in Finder when I right click on a folder or files (it will take even multiple folders and files and run the dropbox lines on them in a seamless way).

Here’s how to do it:

  1. Launch Automator and select Quick Launch
Start up Automator and select Quick Action

2. On the left side of the Actions find Run Shell Script and drag it into the right panel to see script actions options. Set the options carefully just as I outlined in the screenshot.

Match settings and replicate the shell script code just like shown

3. To highlight options here:

  • Workflow received current Files or Folders in Finder
  • Image and color you can set to your liking
  • Pass input: is as arguments
  • Shell script is as follows:
for f in "$@"
do
xattr -w com.dropbox.ignored 1 "$f"
done

4. This will be our Dropbox Ignore action on the context menu of Finder so do command+s and name it whatever you like, I named it “Dropbox Ignore”

5. Repeat the process again by creating a new quick action with the same settings but slightly different script:

for f in "$@"
do
attr -r com.dropbox.ignored "$f"
done

6. Save this quick action and name it again whatever you like. I named mine “Dropbox Unignore”

Perfect! That’s all there is to it. Now let’s see it in action

So there we are. Unlike my previous solution to this problem, this one doesn’t require you to replicate the files, use a 3rd party program in between your files and dropbox and works actually pretty well.

Downsides

This approach however is not perfect but it’s close. One thing to keep in mind is that if you recreate the folder you have to re-set the Dropbox ignore attribute so it won’t sync. Not a big deal but something to keep in mind as traditional git ignore has a file that it checks but Dropbox approach is based on actual file attributes.

Some people might consider it a downside but obviously setting it like the new approach you have to manually mark excluded file/s or folder/s from syncing. Past 2 years have really showed me that I didn’t need to exclude ALL vendor or node_modules folders in my projects as most of them were not changing often enough to even matter. They were synced once and that was it so it wasn’t slowing me down, I ended up only ignoring one or two modules and vendor folders and I did want others to sync because when I accessed on my other machines I would just rebuild the ones I know I ignored and were changing often, the other ones would be fine. (Again, this was a downside for me on my previous approach).

New vs Old

Take a Wordpress example to be easiest. A project with Wordpress might have vendor folders throughout with plugins and similar, the same with node_modules (although less so because php dependencies are required to work while node_modules dependencies affect the build process) but you get my point. My previous approach would require me to go through the project and possibly rebuild vendor folders to make it work on a new machine. The new approach allows me more flexibility but I get why some people might see it as a downside.

Conclusion

So far this seems to be the most elegant solution for me. It works really well. It’s quick, out of the way and actions/automator approach has made it easy for me to turn them on and off as I need to.

Happens when you try to Dropbox Unignore a file that doesn’t have ignore flag attribute on it

There are some improvements I might do in the simple scripts I put in the Automator to avoid errors when you try to unignore a folder or file that doesn’t have the dropbox ignore attribute (see image above) but that doesn’t really bother me as much because I can always see what’s ignored and what’s not.

I think this is as close as we will get to .dropboxignore approach we really waited all this time. But I’ll take it.

--

--

Boz Bundalo

Senior developer and designer @ Futureman Digital, CTO at Hinge Capital (formerly Venture51), tech nerd and a mean cook ;)

Recommended from Medium

Lists

See more recommendations