Utility: Finding untagged files and folders at the command-line

How do you find untagged items? This question popped up in #macdev for someone working on a Dropbox-based backup system of all things. So how do you find just those items in a folder that are untagged? Use mdfind:

mdfind -onlyin . "kMDItemUserTags != '*'" | open -f

If you switch that inequality to ==, you’ll retrieve all tagged items instead.

Folderol makes extensive use of tags. You can search for specific tags using names within the single parens, e.g. to find all the Green system tags:

mdfind -onlyin . "kMDItemUserTags == 'Green'" | open -f

The built in tag names are Red, Orange, Yellow, Green, Blue, Purple, and Gray, but you can assign any tag name you like in Get Info or by using the tag field in Folderol. Then, with a liberal use of asterisks, you can search for, for example, items with tags that contain the word Neon or neon (the [c] means case insensitive).

mdfind -onlyin . "kMDItemUserTags ==[c] '*Neon*'" | open -f

Or tags that start with Neon

mdfind -onlyin . "kMDItemUserTags == 'Neon*'" | open -f

Or end with Neon

mdfind -onlyin . "kMDItemUserTags == 'Neon*'" | open -f

In addition to the [c], you can use [d] (or [cd]) to add diacritical insensitivity, so a search for “café” would also match “cafe”.

To find all Folderol-set custom color tags, search for “(*)”. This excludes standard system tags, although if you’ve tagged with both a custom tag and a system one, the file or folder will appear in the results.

mdfind -onlyin . "kMDItemUserTags == '*(\*)*'" | open -f

Comments are closed.