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

前端 未结 5 1686
太阳男子
太阳男子 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:58

    You can use the URL Resource API, which was introduced in Mac OS X 10.6.

    NSURL* fileURL = [NSURL fileURLWithPath:@"/Path/to/file"];
    
    id labelValue = nil;
    NSError* error;
    if([fileURL getResourceValue:&labelValue forKey:NSURLLabelNumberKey error:&error])
    {
        NSLog(@"The label value is %@",labelValue);
    }
    else
    {
        NSLog(@"An error occurred: %@",[error localizedDescription]);
    }
    

    You can use both the NSURLLabelNumberKey to get the number of the Finder's assigned label or the NSURLLabelColorKey to get the actual color.

    You can set the label values by using the corresponding method:

    - (BOOL)setResourceValue:(id)value forKey:(NSString *)key error:(NSError **)error
    

提交回复
热议问题