pythonmacostagsfinder

How to get list of files on Mac that have been tagged by Finder with a color?


I'd like to tag some files on my Mac with Finder under a certain color tag, and then be able to get that list of files using a Python or bash script. Is it possible to get the list of tags associated with a file via the command line or a Python script?


Solution

  • It's possible.

    But you'll have to rely on xattr, xattr-lib should do the trick.
    Some examples have already been made on how to use the xattr command line tool, those can be found here:

    I hope these help you out.
    In worse case you could use a tool called tag:

    tag -l file # list
    tag -a tag1 file # add
    tag -s red,blue file # set
    tag -r \* file # remove all tags
    tag -f green # find all files with the green tag
    tag -f \* # find all files with tags
    tag -m red * # match (print files in * that have the red tag)
    

    This in combination with say subprocess.Popen could solve your needs.