How can I conditionally color files and folders in the OS X Finder?

前端 未结 5 1683
太阳男子
太阳男子 2020-12-17 05:05

I want to color badge files and folders based on the some condition in finder, what is the approach to achieve this in Mac OS X 10.6

I have checked this question: Th

5条回答
  •  攒了一身酷
    2020-12-17 05:57

    For anybody still needing an answer to this here you go.

    NSURL *fileURL = [NSURL fileURLWithPath:path_to_file];
    NSError *error;
    id labelColor = nil;
    
    [fileURL setResourceValue:@2 forKey:NSURLLabelNumberKey error:&error]; //Set tag/label to green
    [fileURL setResourceValue:@6 forKey:NSURLLabelNumberKey error:&error]; //Set tag/label to red
    

    Garrett Hyde has the correct order.

    //  0 none, 1 grey, 2 green, 3 purple, 4 blue, 5 yellow, 6 red, 7 orange
    

    The above code has been tested using Xcode 4.6.3 and OSX 10.9.2 Mavericks.

提交回复
热议问题