如果文件类型不存在,则颜色标签为绿色

时间:2011-12-04 06:50:28

标签: macos applescript finder

我正在尝试找到一个脚本,当通过Hazel(在OS X上)运行时,在文件夹中查找文件类型.partial,如果找不到,则标记内容该文件夹为绿色,以便Hazel可以用它做其他事情。

1 个答案:

答案 0 :(得分:1)

Applescript Editor

中运行此操作
set myFolder to choose folder
tell application "Finder"
set folderContents to the entire contents of myFolder
end tell
set folderItems to the number of items in folderContents
set x to 1
repeat
    set myFile to (item x of folderContents)
    set theFileName to myFile as text
    if (text ((offset of "." in theFileName) + 1) thru -1 of theFileName) is equal to "partial" then
        return
    end if
    if x is equal to folderItems then exit repeat
    set x to (x + 1)
end repeat
tell application "Finder"
    set y to 1
    repeat
        set greenRepeat to item y of folderContents
        set label index of greenRepeat to 6 --green
        if y is equal to folderItems then exit repeat
        set y to (y + 1)
    end repeat
end tell

此脚本将告诉您选择一个文件夹。然后它会遍历该文件夹中的所有文件,如果找不到类型为.partial的文件,它会将该文件夹中的所有文件的颜色设置为绿色。