2009-09-23 9 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 
相關問題