Can I make the Finder label a folder if it contains a file or folder of a specific name?

Solution 1:

Saw this question and realized the answer would be useful to me too. Here's the Applescript I came up with. Copy it into Applescript Editor, and adjust the two variables theSearchPath (first line) and the index number at the end of the set label index line and you should be good to go.

I'm searching ~/projects and coloring the results green in this case.

set theSearchPath to "/Users/Me/projects"
set theResults to do shell script "find " & quoted form of theSearchPath & " -name .git"

repeat with i from 1 to (count paragraphs of theResults)
  set theResult to paragraph i of theResults
  set theParentPath to text 1 through ((length of theResult) - 5) of theResult
  set theParentAlias to POSIX file (theParentPath) as alias
  tell application "Finder"
    set label index of theParentAlias to 6
    -- Set the last value of the above line to correspond with the color you want.
    -- 0 is no color
    -- 1 is orange
    -- 2 is red
    -- 3 is yellow
    -- 4 is blue
    -- 5 is purple
    -- 6 is green
    -- 7 is gray
  end tell
end repeat

Note: It hasn't been written to gracefully handle errors spit out by the find command. As long as you're searching directories you have permissions on, this shouldn't be an issue.