f you have used Mac OS X before, you’d definitely have used Finder. You’ll realize that in Finder, you can add labels and colors to files and folders. By adding those things to your file, what Mac OS X does is it adds what we call “Extended Attributes” or EAs to the file. However, adding EAs doesn’t cause problems until you need to put those files into an SCM, and use the file on other platforms. We just had this problem today at work when my coworker checked in files that have color labels into Perforce, and when the file is checked out on one of our Linux machines, one file becomes two. For example, a file named background.png becomes background.png and %background.png. Usually, this doesn’t cause problems; however, with Android, you have to put specific files into specific folders so the Android resource packager and resource compiler can understand it, and Android does NOT support resource files starting with anything other than an alphanumeric character. So the program doesn’t compile!
I’ll call this issue “Findergate” to imitate the “antennagate” and “localtiongate” problem Apple had. We need to find a way to fix it. What I found is that there is a way to strip off all of the extra metadata that Finder and other Mac OS X applications put into the file. First, we need a tool to look at what attributes we have in our file. The command to use is
It should display what the file has. For example, I’ve set the green label to one of my file and when I run the command on my file, here’s what I get:
[~/Desktop] $ xattr A.JPG com.apple.FinderInfo
I’m not going to tell you how to set the attribute, but how to remove it. To remove an EA from a file, one can use the command:
[~/Desktop] $ xattr A.JPG com.apple.FinderInfo [~/Desktop] $ xattr -d com.apple.FinderInfo A.JPG [~/Desktop] $ xattr A.JPG [~/Desktop] $
You can see that after using the attr -d command, the EA got removed from the file.
One other way to do it is to use cp -X command. When adding a -X parameter to the cp command, it will strip out all Extended attributes and resource forks of that file. So you can copy the file onto some other directories and it will remove all extra informations about that file that stores there. This is the most efficient way to do it if you have a large amount of files, and each file contains more than one EAs or files contain resource forks. Now let’s see the result of using cp -X
[~/Desktop] $ xattr A.JPG com.apple.FinderInfo [~/Desktop] $ cp -X A.JPG B.JPG [~/Desktop] $ xattr B.JPG [~/Desktop] $
After you’re done copying, you can delete the original files using the rm command.