Skip to content

Instantly share code, notes, and snippets.

@craigerskine
Last active December 21, 2023 19:40
Show Gist options
  • Save craigerskine/fe1278ca405d58cd61e349797f96d9d0 to your computer and use it in GitHub Desktop.
Save craigerskine/fe1278ca405d58cd61e349797f96d9d0 to your computer and use it in GitHub Desktop.
Force Dropbox to truly ignore node_modules using Apple Script (macOS only)
# Prep dropbox to ignore 'node_modules' in a node project
# 1. Move this script to your node project root;
# 2. Delete the existing 'node_modules' folder;
# 3. Run this script;
# 4. `npm install` as normal;
# 5. Enjoy!
tell application "Finder"
set current_path to container of (path to me) as alias
make new folder at current_path with properties {name:"node_modules"}
set current_path to POSIX path of current_path
end tell
delay 1
# do shell script "xattr -w com.dropbox.ignored 1 " & current_path & "./node_modules"
do shell script "xattr -w com.dropbox.ignored 1 " & quoted form of (POSIX path of current_path) & "./node_modules"
@derp-derp-derp
Copy link

derp-derp-derp commented Mar 28, 2020

This is great @craigerskine - thank you for sharing.

I noticed that it won't work for project paths like this one on my system though:
/Users/johndoe/Dropbox/1 - Cordova iPhone Apps/My App/

The specific error is:
xattr: No such file: Cordova/./node_modules (1)r: xattr: No such file: '/Users/johndoe/Dropbox/1

Do you know if it's the space(s) or the hyphen causing the problem, and in either case how to fix?

@derp-derp-derp
Copy link

@craigerskine I got it to work by changing line 16 to:
do shell script "xattr -w com.dropbox.ignored 1 " & quoted form of (POSIX path of current_path) & "./node_modules"

Credit to this SO post:
https://apple.stackexchange.com/a/200505

Thanks again! Very useful gist.

@craigerskine
Copy link
Author

@derp-derp-derp
Thanks for the contribution, I truly appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment