我想在脚本中包含对文件输入的检查,以查看文件/文件夹是否有颜色集,是否有颜色集,是哪一个...(我不需要帮助创建此脚本,只需要命令来检查标签的颜色。)
例如,像这些颜色(灰色): http://img.skitch.com/20090923-t1xsphn47tdq64b8ksb43wh3e8.png
我想避免使用Apple脚本。
答案 0 :(得分:5)
使用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
答案 1 :(得分:5)
mdls -name kMDItemFSLabel -raw "[filename or directory]"
...将输出标签的编号。将它分配给这样的变量:
LABEL_NUMBER=$(mdls -name kMDItemFSLabel -raw "[filename or directory]")
echo $LABEL_NUMBER
答案 2 :(得分:2)
您还可以使用“mdls filename ”并查找kMDItemFSLabel值。如果有人知道某种方法,我正在寻找一种通过命令行更改标签的方法。
答案 3 :(得分:2)
我使这个脚本将文件或文件夹的标签索引作为整数返回:
0 = no colour
1 = orange
2 = red
3 = yellow
4 = blue
5 = purple
6 = green
7 = grey
您需要做的就是:
#!
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
}
所以现在你可以做类似的事情:
#!
if [ `~/bin/getlabel $1` == 2 ]; then
echo yup
else
echo nope
fi