2009-09-23 12 views

回答

4

使用xattr ...例如,我有一个名为“Foo”的目录,并且我在Finder中将其标签设为红色。然后我做:

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 

然后我做到了蓝色,你可以看到相关的字节变化:

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

+0

哦哇,这是深刻的,谢谢。 但似乎有伎俩。 颜色会始终显示在同一个字节上吗? – Mint 2009-10-02 22:45:31

+0

我不知道,我刚开始玩它,这就是我发现的。 – 2009-10-03 05:11:50

+0

好吧,它现在好像工作了,再次感谢。 – Mint 2009-10-03 10:21:59

2

您还可以使用 “MDLS ” 和查找kMDItemFSLabel值。如果有人知道某种方法,我正在寻找一种通过命令行更改标签的方法。

1

我做了这个脚本返回文件或文件夹的标签索引的整数,其中:

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

所有你需要做的是:

#! 
getlabel() { 
    osascript - "[email protected]" << 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 
} 

所以现在你可以做的东西像:

#! 
if [ `~/bin/getlabel $1` == 2 ]; then 
    echo yup 
else 
    echo nope 
fi 
5
mdls -name kMDItemFSLabel -raw "[filename or directory]" 

...将输出标签的编号。将其分配给像这样的变量:

LABEL_NUMBER=$(mdls -name kMDItemFSLabel -raw "[filename or directory]") 
echo $LABEL_NUMBER 
相关问题