Skip to content

Instantly share code, notes, and snippets.

Last active October 4, 2020 05:42
Show Gist options
  • Save todbot/dc01669ff90823bb8f7e8dd9dd3d7f59 to your computer and use it in GitHub Desktop.
Save todbot/dc01669ff90823bb8f7e8dd9dd3d7f59 to your computer and use it in GitHub Desktop.

Prevent Annoying Mac ._ files being created on CIRCUITPY

Unzip & Download files to CIRCUITPY

The entire process in a single session, using a neopixel example:

% unzip
% xattr -cr adafruit-circuitpython-bundle-6.x-mpy-20201003
% cd adafruit-circuitpython-bundle-6.x-mpy-20201003
% cp lib/{neopixel.mpy, adafruit_pypixelbuf.mpy} /Volumes/CIRCUITPY/lib
% cp examples/ /Volumes/CIRCUITPY/


On the Mac, the OS stores a bunch of different meta information about files inside those files. These are called "Extended Attributes" or "xattrs". If you copy a file on a Mac to a thumbdrive or network share that doesn't support extended attributes, macOS attempts to convert those xattrs to a plain file format. That's what the ._ and .DS_Store files are.

These files are normally just an annoyance, but on CircuitPython devices with small flash storage space, like the Trinket M0 or QT Py, it can be a real problem.

The Process

  1. If you have a folder on your Mac with files you want to copy over, do not use the Finder to copy the files, or look at the directory those files are in, or to look at the CIRCUITPY drive. Instead you must use the commandline. Any time the Finder shows you files, it may recreate these xattrs.

  2. Use system tool xattrs to look at extended attributes For instance, let's say you just downloaded and unzipped the latest CircuitPython library bundle. In the Terminal, you can run xattr -r on the directory to see all xattrs on all files. The below shows how they all have the quarantine attribute set because it's a file downloaded from the Internet.

    % xattr -r adafruit-circuitpython-bundle-6.x-mpy-20201003
  3. Delete Extended Attributes with xattrs -c Now you can delete these attributes on all files in a directory with one command: But you must quickly copy the file after doing so before the Finder recreates them.

    % xattr -cr adafruit-circuitpython-bundle-6.x-mpy-20201003
  4. Removing existing ._ files on your CIRCUITPY drive If you accidentily copied files without using xattr -c first and you have ._ files, instead of deleting them by hand, you can use the system tool dot_clean:

    % dot_clean /Volumes/CIRCUITPY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment