Are the OSX Mavericks tags visible from the command line?

For example, suppose I have a directory structure such as

/Users
    /tlehman
        /Math
            algebraic_varieties.tex [tagged: Math, Documentation]
            projective_geometry.pdf [tagged: Math]
        /Development
            visualize_surfaces.py   [tagged: Math, Programming]
            solve_polynomials.scm   [tagged: Math]
    /guest
        /Desktop
            welcome.rtf             [tagged: Documentation]
/Volumes
    /USBKey
        assignments_for_may.txt     [tagged: Math]
        using_LaTeX.pdf             [tagged: Documentation]

From the command line, is there a way I can use ls (or something like it) to display all the files tagged as "Math"?

EDIT: I made a tool called tfind that does this: https://github.com/tlehman/bin/blob/master/tfind


I'm assuming they will be an xattr like they currently are on 10.8.3 (and older)

Currently, you can view which extended attributes a file has with ls -l@.

But to see the contents of the attributes, you have to use xattr.


Yes, you can find files that have a given user tag using mdfind.

Create a file and assign it a a custom tag in Finder.

Then go in a terminal; you will find it with:

mdfind "kMDItemUserTags == Math || kMDItemUserTags == Programming"

or

mdfind "kMDItemUserTags == Math && kMDItemUserTags == Programming"

See also -onlyin aFolder to restrict the search.

I didn't check how complex these boolean expressions can be, but these two examples work.

You can pipe the output to ls like this:

mdfind "kMDItemUserTags == mathTag || kMDItemUserTags == anotherTag" \
| while read f; do ls "$f"; md5 "$f"; done

Also, mdfind has an option "-0"

    -0                Use NUL (``\0'') as a path separator, for use with xargs -0.

which can be practical with nasty filenames.


You can get all tags of a file with:

mdls -name kMDItemUserTags filename