9

Now that Mavericks removed that ugly colored bar and replaced it with a nice looking dot, I would like to use tags more.

Basically I have work files in different places that deal with different projects and I would like to apply the tag for all the files included in specific folders. The files may move around into new folders (outside of the original folder) in the future so I would like to apply a tag recursively to a folder so that I can find it easier if it gets moved out of its folder.

7

You can use xattr to write various metadata related to the "new" tags in Mavericks. John Siracusa did the heavily lifting already here.

Essentially you need to write two attributes, com.apple.FinderInfo and com.apple.metadata:_kMDItemUserTags, to the files. The easiest way is going to be to get a file tagged how you want and just copy the attributes from it. Open up terminal and change to the directory containing the folder you want to tag recursively. Then enter:

touch sampleFile
open .

That will open up Finder so you can tag the sampleFile how you want all the other files to be tagged. After you're done tagging, switch back to your terminal window and enter:

find yourDirName -type f | xargs xattr -wx com.apple.FinderInfo \
"`xattr -px sampleFile`"

find yourDirName -type f | xargs xattr -wx com.apple.metadata:_kMDItemUserTags \
"`xattr -px com.apple.metadata:_kMDItemUserTags sampleFile`"

That will recursively drill down and tag all the files in yourDirName as well as files in any subdirectories. You can leave the -type f argument off if you want to tag the subdirectories as well as the files.

Finally, you can change the

find yourDirName -type f

commands to

find yourDirName -iname "*.ext"

if you want to only tag certain file types/extensions.

  • Love it. I read the same Ars review and I was wondering how I could attach the metadata needed to each file. – Steve W. Oct 28 '13 at 12:32
10

There's a CLI tag tool available via Macports/Homebrew: https://github.com/jdberry/tag

It doesn't seem to have a recursion option, however, I would imagine you could use this in conjunction with the standard UNIX 'find'.

e.g., (from inside the directory you want to tag files in)

find . -exec tag --add tagname {} \;  -print 
  • The current version (tag v0.8.1) supports recursive tagging using tag -e -d --add tagname path – Munkymorgy Aug 15 '16 at 19:24
3

One simple way to do this is to use a Spotlight search to generate a list of all the files you're interested in. An example of how to do this:

  • In Finder, navigate to the top of the folder structure you're interested in.
  • Type -kind:folder in the Spotlight search field

    This will search for all files that are not a folder (the - sign negates the results).

  • Make sure you then restrict the search to the folder hierarchy you're interested in by clicking on the name of the folder in the search terms just underneath the Spotlight search field.

You will now have a list in your Finder window of all the files within that folder hierarchy. Now it is trivial to select all the files, and apply the tags you want in the usual way with Finder.

Use different Spotlight searches to suit your needs.

You can make this process slightly easier by making Spotlight always search in the current folder and not This Mac:

Finder -> Preferences -> Advanced -> When performing a search: Search the current folder

1

Go to the top folder and search for '.' within that folder.

Select all of the files and tag 'em.

You might need to remove the tag then reapply it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .