Prevent annoying Mac ._ files on CIRCUITPY

Example: Unzip & Download files to CIRCUITPY

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

% unzip adafruit-circuitpython-bundle-6.x-mpy-20201003.zip
% 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/neopixel_simpletest.py /Volumes/CIRCUITPY/code.py

(Or like JP suggests in the comments, you can use “cp -X” to not copy extended attributes: e.g. cp -X /examples/neopixel_simpletest.py /Volumes/CIRCUITPY )

Background

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 for CircuitPython devices with little flash storage space, like the Trinket M0 or QT Py, it can be a real problem. So here’s some tips.

Treat files as contaminated and No Finder

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

See extended attributes with xattrs

The system tool xattrs lets you examine 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 attributes on all files in that directory. The example 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
adafruit-circuitpython-bundle-6.x-mpy-20201003/VERSIONS.txt: com.apple.quarantine
adafruit-circuitpython-bundle-6.x-mpy-20201003/examples/lsm303_simpletest.py: com.apple.quarantine
adafruit-circuitpython-bundle-6.x-mpy-20201003/examples/is31fl3731_pillow_numbers.py: com.apple.quarantine
[...]

Delete extended attributes with xattrs

You can delete these attributes on all files in a directory with one command. Copy the files immediately after doing so before the Finder recreates them.

% xattr -cr adafruit-circuitpython-bundle-6.x-mpy-20201003

Remove existing ._ files with dot_clean

If you accidentally copied files without using xattr -c or otherwise have ._ files. You can delete them by hand or use the system tool dot_clean to remove them from the whole drive:

% dot_clean /Volumes/CIRCUITPY

Any time it feels you’re running low on CIRCUITPY disk space, check to see it’s not full of these dang meta info files.

Most of the stuff about xattr came from this nice post by JayRizzo on StackOverflow.

3 Replies to “Prevent annoying Mac ._ files on CIRCUITPY”

  1. Thanks for the info! You can also copy files using the “-X” option.

    -X Do not copy Extended Attributes (EAs) or resource forks.

    cp -X /Volumes/CIRCUITPY

Leave a Reply

Your email address will not be published. Required fields are marked *