Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see what label color is on a file/folder from within Termnal (Mac OS X)

I want to include in a script a check for a file input to see if the file/folder has a color set and if it does, which one... (I don't need help with the creation of this script, just need the command to check what color the label is).

eg, like these colors (grey): http://img.skitch.com/20090923-t1xsphn47tdq64b8ksb43wh3e8.png

I would like to avoid using apple script.

like image 329
Mint Avatar asked Dec 09 '22 19:12

Mint


2 Answers

Using xattr... for instance, I have a directory named "Foo", and I made its label red in the Finder. Then I did:

wilPureSex% xattr -p com.apple.FinderInfo Foo
00 00 00 00 00 00 00 00 00 0C 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Then I made it blue, and you can see the relevant byte change:

wilPureSex% xattr -p com.apple.FinderInfo Foo
00 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

-Wil

like image 151
Wil Shipley Avatar answered Dec 12 '22 07:12

Wil Shipley


mdls -name kMDItemFSLabel -raw "[filename or directory]"

... will output the number of the label. assign it to a variable like this:

LABEL_NUMBER=$(mdls -name kMDItemFSLabel -raw "[filename or directory]")
echo $LABEL_NUMBER
like image 44
mattes Avatar answered Dec 12 '22 08:12

mattes