How to find out what shortcut color is in a file / folder from Termnal (Mac OS X)

I want to include a check on the input of the file in the script to find out if a file / folder with color is installed, and if so, which one ... (I do not need help creating this script, I just need a command to check which color has label).

e.g. like these colors (gray): http://img.skitch.com/20090923-t1xsphn47tdq64b8ksb43wh3e8.png

I would like to avoid using apple script.

+4
source share
4 answers

Using xattr ... for example, I have a directory named "Foo" and I made its shortcut red in 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 corresponding 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

+4
source
 mdls -name kMDItemFSLabel -raw "[filename or directory]" 

... will display the tag number. assign it the following variable:

 LABEL_NUMBER=$(mdls -name kMDItemFSLabel -raw "[filename or directory]") echo $LABEL_NUMBER 
+5
source

You can also use "mdls filename" and look for the value of kMDItemFSLabel. I am looking for a way to change a shortcut via the command line if anyone knows about the method.

+2
source

I made this script to return the index of the file or folder label as an integer, where:

 0 = no colour 1 = orange 2 = red 3 = yellow 4 = blue 5 = purple 6 = green 7 = grey 

All you have to do is:

 #! getlabel() { osascript - " $@ " << EOF on run argv tell application "Finder" set theArg to POSIX file ((do shell script "pwd") & "/" & argv) as alias set labelIndex to (get label index of theArg) do shell script("echo " & labelIndex) end tell end run EOF } 

So now you can do things like:

 #! if [ `~/bin/getlabel $1` == 2 ]; then echo yup else echo nope fi 
+1
source

All Articles