Mac OS X : 터미널에서 파일의 색상 레이블을 변경하는 방법 있습니까? 다음 명령은

터미널에있을 때 파일의 색상 레이블을 색상으로 설정할 수있는 방법이 있습니까?

다음 명령은 현재 색상이 무엇인지에 대한 정보를 나열하지만 색상에 대한 작업 방법을 알 수는 없습니다. 그것을 바꾸는 것처럼.

mdls -name kMDItemFSLabel somefile.ext

내가 알고 싶은 이유는 특정 유형의 폴더에있는 모든 파일을 특정 색상 레이블 (제 경우 회색)로 재귀 적으로 표시하고 싶기 때문입니다.

나는 찾는 방법을 알고 있습니다.

find . -name "*.ext"

그리고를 사용하여 각 파일에 대해 나중에 명령을 실행할 수있는 -exec방법을 알고 있지만 실제 레이블 지정 방법을 알아야합니다 …

Mac OS X에 내장 된 명령 만 포함 된 솔루션을 원합니다. 다른 방법이없는 한 타사 제품이없는 것이 좋습니다.



답변

여기 및 참조 된 게시물의 응답을 기반으로 다음 기능을 수행하여 ~ / .bash_profile 파일에 추가했습니다.

# 파인더 라벨 색상 설정
상표(){
  [$ # -lt 2]이면; 그때
    echo "사용 : 레이블 [0-7] file1 [file2] ..."
    echo "파일의 파인더 레이블 (색상)을 설정합니다"
    에코 "기본 색상 :"
    에코 "0 색상 없음"
    에코 "1 주황색"
    에코 "2 빨간색"
    에코 "3 노랑"
    에코 "4 블루"
    에코 "5 퍼플"
    에코 "6 녹색"
    에코 "7 그레이"
  그밖에
    osascript- "$ @"<< EOF
    실행중인 argv
        labelIndex를 (arrgv의 항목 1을 숫자로) 설정
        2에서 (argv의 수)까지 i로 반복
          응용 프로그램 "파인더"를 알려
              파일을 별명으로 POSIX 파일 (arrgv의 항목 i)로 설정하십시오.
              파일의 레이블 색인을 labelIndex로 설정
          말하다
        끝 반복
    최종 실행
EOF
  fi
}

>


답변

Mavericks AppleScript에서 osascript 메서드가 손상된 것 같지만 작동하는 것 같습니다

xattr -wx com.apple.FinderInfo "0000000000000000000C00000000000000000000000000000000000000000000" /path/to/your/file

매버릭스에서 이것은 파일 레이블을 이전 레이블과 병합하는 것으로 보이며 (현재 “태그”이므로) 동일한 토큰으로 애플이 이런 식으로 확장 속성 사용을 중지하면 위의 부분이 깨질 것으로 예상됩니다. 그러나 그것은 지금 나를 위해 일하고 AS보다 훨씬 빠르다는 이점이 있습니다.


답변

osascript -e “tell app \”Finder \ “를 사용하여 POSIX 파일 (\”/ junk.txt \ “)의 레이블 색인을 1″로 설정하십시오.


답변

@Lauri와 @Robert의 두 가지를 기반으로 한 내 버전이 있습니다. 숫자가 아닌 색 이름을 사용하여 색을 지정합니다. 색상 이름은의 출력과 일치 hfsdata -L하므로 “없음”을 사용하여 파일에 색상을 지정하지 않습니다. 이것을 “setlabel”이라는 파일에 저장하고 수행하십시오 chmod 755 setlabel.

#!/bin/bash
# Set Finder label color
  if [ $# -lt 2 ]; then
    echo "USAGE: setlabel color file1 [file2] ..."
    echo "Sets the Finder label (color) for files"
    echo "Possible colors: None Orange Red Yellow Blue Purple Green Gray"
  else
  labelargs=$@
  color=$1
  file=$2
  colorarray=( None Orange Red Yellow Blue Purple Green Gray )
  colorvalue=8
  for i in {0..7}
     do
      if [ "${color}" == ${colorarray[${i}]} ]
      then
         colorvalue=${i}
      fi
     done
  if [ "${colorvalue}" == "8" ]
      then
         echo Color ${color} is not recognized.
     echo "Possible colors: None Orange Red Yellow Blue Purple Green Gray"
     else
    osascript - ${colorvalue} ${file} << EOF >/dev/null 2>&1
    on run argv
        set labelIndex to (item 1 of argv as number)
        repeat with i from 2 to (count of argv)
          tell application "Finder"
              set theFile to POSIX file (item i of argv) as alias
              set label index of theFile to labelIndex
          end tell
        end repeat
    end run
EOF
    fi
  fi


답변

xattr -l 또는 xattr -p com.apple.FinderInfo를 사용하여 Finder에서 볼 수 있습니다 (xattr -l 또는 xattr -p com.apple.FinderInfo), 0 (1E) 사이에 플래그를 얻습니다. colour .. 제 3 자 자료 : hfsdebug (sudo와 함께 사용)는 읽을 수있는 색상 레이블 중 많은 정보를 얻습니다.

세 번째 부분으로 변경하려면 : osxutils 에는 setlabel 명령이 있습니다.


답변

Finder와 동일한 순서로 색상을 사용합니다.

#!/bin/bash

if [[ $# -le 1 || ! "$1" =~ ^[0-7]$ ]]; then
  echo "usage: label 01234567 FILE..." 1>&2
  exit 1
fi

colors=( 0 2 1 3 6 4 5 7 )
n=${colors[$1]}
shift

osascript - "$@" <<END > /dev/null 2>&1
on run arguments
tell app "Finder"
repeat with f in arguments
set f to (posix file (contents of f) as alias)
set label index of f to $n
end
end
end
END

상대 경로를 별명으로 변환하면 CFURLGetFSRef가 10.8에 체계가없는이 URL을 전달한 것과 같은 경고가 발생하므로 stderr가 경로 재 지정됩니다 . osascript가 마지막 표현식의 값을 인쇄하기 때문에 stdout이 리디렉션됩니다.


답변

나는이 스크립트를 좋아하지만 스크립트 내에서 bash의 IFS 설정을 변경하고 파일 이름 목록이있는 텍스트 파일을 허용하도록 파일 입력을 변경하기 전까지는 이름에서 공백을 사용한 파일에서 작동하지 않았습니다.

#!/bin/bash
# Set Finder label color of files in a list
# set the Internal Field Separator to \n (newline)
IFS=$'\n'
  if [ $# -lt 2 ]; then
    echo "USAGE: LabelFilelist color Path/to/filelist ..."
    echo "Sets the Finder label (color) for files"
    echo "Possible colors: None Orange Red Yellow Blue Purple Green Gray"
  else

 labelargs=$@
  color=$1
  file=`cat < $2`
  colorarray=( None Orange Red Yellow Blue Purple Green Gray )
  colorvalue=8
  for i in {0..7}
     do
      if [ "${color}" == ${colorarray[${i}]} ]
      then
         colorvalue=${i}
      fi
     done
  if [ "${colorvalue}" == "8" ]
      then
         echo Color ${color} is not recognized.
     echo "Possible colors: None Orange Red Yellow Blue Purple Green Gray"
     else
    osascript - ${colorvalue} ${file} << EOF >/dev/null 2>&1
    on run argv
        set labelIndex to (item 1 of argv as number)
        repeat with i from 2 to (count of argv)
          tell application "Finder"
              set theFile to POSIX file (item i of argv) as alias
              set label index of theFile to labelIndex
          end tell
        end repeat
    end run
EOF
    fi
  fi