2

I'd like to programmatically set the Finder label (a.k.a. the color of items in the Finder) from within Cocoa. I can read the Finder label of a URL u without problems using

MDItemRef itemRef = MDItemCreateWithURL(NULL, (CFURLRef)u);
CFStringRef s = MDItemCopyAttribute(itemRef, kMDItemFSLabel);
label = [(NSString *)s intValue];

This API does not provide any mechanism for writing the metadata, so my guess is that the solution lies elsewhere entirely. Any hints?

Edit: I know this is possible using AppleScript, but this is disallowed under sandboxing. I need a pure in-process solution.

Aderstedt
  • 6,301
  • 5
  • 28
  • 44
  • For 10.6+, try http://stackoverflow.com/a/2785289/483349. – Evan Mulawski Mar 23 '12 at 11:36
  • Thanks, that was fast. If you make your comment in answer form, I'll accept it. – Aderstedt Mar 23 '12 at 11:39
  • possible duplicate of [How can I conditionally color files and folders in the OS X Finder?](http://stackoverflow.com/questions/2778855/how-can-i-conditionally-color-files-and-folders-in-the-os-x-finder) – jscs Mar 23 '12 at 18:19

1 Answers1

1

For Snow Leopard and above, you can utilize the URL Resource API, as seen in this answer.

Community
  • 1
  • 1
Evan Mulawski
  • 54,662
  • 15
  • 117
  • 144