Disappearing color labels in Mac OS X

Had a tiny fight with Mac OS X the other day, like I often do. This time it was color labels. You probably know (if you have used Mac OS X at all) that you can color label your files. You simply right-click them in the Finder and select a color label.

This can be quite a handy feature, but not so much when it doesn’t work. My problem was that I would give a bunch of files color labels, but then shortly after that the label simply disappeared. I could look at the file in the Finder, it had its label, I’d click on it, and the label disappeared. In fact the color label was already gone, it was just that the Finder is kind of slow to update itself… O’ how I miss F5 sometimes…

Anyways, you can check if a file really has a label or not by opening up a Terminal and using the following command on the file in question:

$ mdls -name kMDItemFSLabel somefile.ext

It will give you back a number and if the number is greater than zero it means the file has a label.

But what to do about it?

After some digging I found that it might have to do with some XSan issues or corrupt meta files. Mac OS X spreads these meta-files around wherever it goes and apparently they go corrupt from time to time. A quick and simple way to fix this issue is just to clear them all out and let Finder have fun recreating them. As these files are hidden in the Finder, and Mac OS X is so kind to not give us an easy way of showing hidden files, I once again opened up a Terminal. I then went to the directory with the broken meta-files and ran these two commands:

$ rm ._*
$ rm .DS_Store

All the labels should then be gone in Finder if you check the folder again. Now re-label them and they should hopefully stay labeled as well. Hope this can help someone else :)

Doing it recursively

The following command will do it for the current working directory and all its sub-directories:

$ find . -name .DS_Store -delete
$ find . -name "._*" -delete

Files with no extension

If you have filenames without an extension, like for example Some video instead of Some video.mov, Finder won’t know how to open these files anymore after you remove the meta-files. If that should happen I recommend that you add the right extension on the filename and you will have no more problems with that. If you prefer to have it without extension you can also select and right-click the files, select Get Info, and then under the Open with category select the application you want the file to be opened with. But seriously, just giving the files proper extensions to begin with is a lot easier to work with… at least I think so…

  • http://www.crx.io Julien Palmas

    I’ve had quite the same issue with files hosted on a time capsule.
    I would label them with the finder, the label would appear, and the moment after, disappear without further notice ….

    I did not know about mdls, thanks !!!, and it confirmed that the file had kept the color label, but it was the finder whom did not display correct info.

    I just re-launched the finder and I saw my labels again !

    Looks like the finder has some issues with color labels on remotely hosted files ….

    • http://www.geekality.net Torleif

      Glad I could help!

  • Richard

    Your solution worked for me. Thanks!

    • http://www.geekality.net Torleif

      Great to hear :)

  • Jessy

    Hi Torleif,

    I have a similar problem on a Mac snow Leopard.
    I used certain label colors for some .m and .txt files.
    If I open and read them everything is fine, meaning that
    the label color is kept. However, as soon as I modify and
    save them, the label color is gone. The mdls command
    shows “null” and the solution of removing .DS_Store
    unfortunately does not work.

    Do you have other ideas?

    Thanks in advance!

    • http://www.geekality.net Torleif

      Tried to remove the ._* files as well? What program do you use to view and save them with?

      • Jessy

        Thanks for the answer, Torleif, but it does not work.
        I understood the problem, but I do know how to find a
        workaround to solve it.
        The files affected by this behaviour are all those
        that I decided to open with gedit. IF I choose Xcode
        (by apple), the problem does not happen anymore.
        Now, is there a way to get permanent color label for files that one decides
        to open with “non-apple” applications?

        Thanks a lot for any comment.

        • http://www.geekality.net Torleif

          Try to run this in the terminal

          ls -li yourfile.txt

          Take note of the first number, which is the inode number of your file. Then try to edit the file with xcode, save your changes and then run that command again. Check if the inode number stayed the same. Then try the same with gedit. Did the inode number change?

          I once tried to mark a file as read-only, but for some reason TextEdit didn’t seem to care. Turned out TextEdit actually creates a new file and just replaces the old file. Maybe this is the case with gedit as well and that the label gets lost in that process?

          You can also check if there is a file called ._yourfile.txt in the same folder as yourfile.txt, that’s where color labels are stored if I have understood correctly. If that file disappears, gets changed or something like that after you edit it with gedit then you at least know why the label goes away.

          • Jessy

            The inode number changes in both cases, using gedit and Xcode to open, edit and save a file. It remains never the same. Moreover, I cannot find any file ._

            Thanks anyway for your help.

            Please, let me know if you came up with some other ideas.

            Thanks a lot for your comments.

          • http://www.geekality.net Torleif

            Strange. Maybe things work differently in Snow Leopard. I did this in 10.4 and 10.5. If your files have a label, there should be ._ files though… remember that they are hidden (since they are starting with a dot). You can list them in the Terminal by using the A switch. For example:

            li -lA

            You can also make them show up in your Finder if you like. I do that sometimes, but usually have it off most of the time since folders become quite cluttered thanks to all the meta files OS X spreads around…

            Anyways, good luck on your quest. Let me know if you figure out what the problem is :)

  • Jessy

    I am quite aware of “ls -a”, that I have used to visualize the . hidden files.
    I guess I have just to survive to have some non labeled color files because I
    won’t leave gedit!

    Thanks anyway!

    Jessy

  • http://www.pigmentacomunicacio.com Xavi Serra

    An easy way to solve the problem:
    1-Cmd+i to open info window of the affected file
    2-On the top of that window you’ll see the tags part
    3-Click on that part, go to “Show all..” and you will find the missed tags ; )