Metadata

A script to add macOS tags and file comments in Yazi

I have a love/hate relationship with the macOS Finder, so I often work in yazi homepage | GitHub. But one of the things that the Finder does do acceptably is to set tags and add Finder comments. I make extensive use of both of these in order to find files and directories more easily. However, yazi doesn’t have exactly the metadata editor that I was looking for. So I wrote one.

File comment metadata on macOS

First, a brief digression on file metadata in macOS - specifically file comment metadata. There are at least two types of file comment metadata available for filesystem entities in macOS - the so-called “Finder comments” also known as “Spotlight comments” which are available in Finder’s “Get Info…” dialog. They are quick, easy, and familiar to most macOS users. They are also very fragile because they are stored in two different places. The primary storage is in a .DS_Store file in the enclosing directory. A second copy is stored in an xattr (extended attribute) com.apple.metadata:kMDItemFinderComment for the file. In computer science, it’s rarely a good idea to have two sources of truth, and sure enough this is where Finder comments go off the rails. If you enter a comment in Finder’s Get Info, then edit the comment with xattr, Finder will never see the change. The Get Info version just shows whatever was initially entered. Worse, since it is stored separately from the file, and .DS_Store files are often excluded from cross-platform sync, the comment disappears.