Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

is there a command line utility for changing the color label of files in macosx?

share|improve this question
Possible duplicate of… Basically, use AppleScript. – NReilingh Jan 17 '11 at 18:05

You can write it yourself. Open /Applications/Utilities/AppleScript and enter the following:

on run argv
    tell application "Finder"
        set theFile to POSIX file (item 1 of argv) as alias
        set labelIdx to (item 2 of argv as number)
        set label index of theFile to labelIdx
    end tell
end run

Save as color.scpt and invoke from Terminal like this:

osascript color.scpt somefile.txt 3

somefile.txt will be colored, 3 is the color: 0 means colorless, 1 through 7 are the Finder's colors (with 1 being red).

share|improve this answer

This article, View and set Labels from the command line, describes a command line utility to do it. Caveat: it's an old article, describing a utility for OS 10.3, and I haven't tried it myself.

share|improve this answer

Based on the responses here and in referenced posts, I made the following function and added it to my ~/.bash_profile file:

# Set Finder label color
  if [ $# -lt 2 ]; then
    echo "USAGE: label [0-7] file1 [file2] ..."
    echo "Sets the Finder label (color) for files"
    echo "Default colors:"
    echo " 0  No color"
    echo " 1  Orange"
    echo " 2  Red"
    echo " 3  Yellow"
    echo " 4  Blue"
    echo " 5  Purple"
    echo " 6  Green"
    echo " 7  Gray"
    osascript - "$@" << EOF
    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

share|improve this answer
Didn't you get the order wrong? Red is before orange, isn't it? – Daniel Beck Mar 10 '11 at 4:33
@Daniel No, the default order of colors sucks. You could actually edit your answer to take it into account. – user495470 Mar 10 '11 at 12:33

You must log in to answer this question.