3

I'd love it if I could somehow make the Finder color-label all folders containing a .git directory so I could tell at a glance if the folder is a Git repo. Any ideas?

  • Use Folder Actions apple.blogoverflow.com/2012/06/… – user588 Jul 2 '12 at 22:52
  • @mankoff thanks for the suggestion, but aren't folder actions tied to specific folders? Or can I make a folder action that is attached to ALL folders, even newly created ones? – bernk Jul 3 '12 at 9:41
  • Oh you are probably right. OK. Perhaps you'll need to code. See SCPlugin, the SVN Finder Plugin. It changes folder and file icons based on SVN status. – user588 Jul 3 '12 at 12:56
  • Or, cron job with a 'find' or 'mdfind' command, calling AppleScript? There are an infinite number of hack-ish ways to do this. Not sure about the best formal method. – user588 Jul 3 '12 at 12:57
2

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.

0

Vickash's script didn't work for me so I updated it, and revised it slightly to be able to find any file extension by specifying the extension in the variable theFileExtension (in my case, .flac files.) Works in Sierra.

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

repeat with i from 1 to (count paragraphs of theResults)
    set theResult to paragraph i of theResults
    set thePath to text 1 through ((length of theResult)) of theResult
    tell application "Finder"
        set theParentAlias to container of (POSIX file (thePath) as alias)
        set label index of theParentAlias to 1
        -- 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .