如果Finder标签包含特定名称的文件或文件夹,我可以将其标记为文件夹吗?


3

我喜欢它,如果我可以以某种方式使Finder颜色标签包含.git目录的所有文件夹,这样我就可以一眼就看出该文件夹是否是Git仓库。有任何想法吗?



@mankoff感谢您的建议,但是文件夹操作不是绑定到特定文件夹吗?或者我可以创建附加到所有文件夹的文件夹操作,甚至是新创建的文件夹吗?
伯克

哦,你可能是对的。好。也许你需要编码。参见SVn Finder插件的SCPlugin。它根据SVN状态更改文件夹和文件图标。

或者,使用'find'或'mdfind'命令调用AppleScript的cron作业?有无数种黑客方法可以做到这一点。不确定最好的正式方法。

Answers:


2

看到这个问题并意识到答案对我也很有用。这是我提出的Applescript。将其复制到Applescript Editor中,并调整两行变量theSearchPath(第一行)和行尾的索引号,set label index你应该好好去。

~/projects在这种情况下,我正在搜索并将结果着色为绿色。

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

注意:尚未编写它以优雅地处理由find命令吐出的错误。只要您正在搜索您拥有权限的目录,这应该不是问题。


0

Vickash的脚本对我不起作用所以我更新了它,并稍微修改它以便能够通过在变量中指定扩展名来找到任何文件扩展名theFileExtension(在我的例子中,.flac文件。)在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
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.