Order of Finder labels

18 views
Skip to first unread message

Fritz Anderson

unread,
Mar 31, 2012, 8:29:32 PM3/31/12
to cocoa-dev@lists.apple.com List
Mac OS 10.7, Xcode 4.3.2

I have an application with which I would like to set Finder labels (colors) for directories. I use the URL resource API to read and write NSURLLabelNumberKey for the target directory. This works, up to a point.

If I set the label number to 0, it behaves as expected: Any label is removed.

If I set the label number to anything else (up to 7), the folder's label is set, but the label numbers don't seem to correspond to any order the Finder uses. Label 3 does not correspond to the third color in the Finder Preferences list, nor does it correspond (as one source suggests) to the third label in alphabetical order by name.

+[NSWorkspace fileLabelColors] returns the available label colors in the same order as the index.

What I'd really like is to use the same order as appears in the preferences, and in the File/contextual menu. That is, I'd like to conform to Apple's interface. Is this possible?

— F


_______________________________________________

Cocoa-dev mailing list (Coco...@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/cocoa-dev-garchive-98506%40googlegroups.com

This email sent to cocoa-dev-ga...@googlegroups.com

Seth Willits

unread,
Mar 31, 2012, 8:53:43 PM3/31/12
to cocoa-dev@lists.apple.com List
On Mar 31, 2012, at 5:29 PM, Fritz Anderson wrote:

> +[NSWorkspace fileLabelColors] returns the available label colors in the same order as the index.
>
> What I'd really like is to use the same order as appears in the preferences, and in the File/contextual menu. That is, I'd like to conform to Apple's interface. Is this possible?

Why wouldn't it be? Just display them in the same order as Finder and don't rely on the display index being the same as the label index you use in the assignment. I don't really see the problem. (I've done this.)


--
Seth Willits

Fritz Anderson

unread,
Apr 1, 2012, 1:33:44 PM4/1/12
to Seth Willits, cocoa-dev@lists.apple.com List
On 31 Mar 2012, at 7:53 PM, Seth Willits wrote:

> On Mar 31, 2012, at 5:29 PM, Fritz Anderson wrote:
>
>> +[NSWorkspace fileLabelColors] returns the available label colors in the same order as the index.
>>
>> What I'd really like is to use the same order as appears in the preferences, and in the File/contextual menu. That is, I'd like to conform to Apple's interface. Is this possible?
>
> Why wouldn't it be? Just display them in the same order as Finder and don't rely on the display index being the same as the label index you use in the assignment. I don't really see the problem. (I've done this.)

Hard-coding the order works in practice — most of the time. Unless I much mistake, it doesn't work in principle. Users can change colors and label names, and I know of no way to sort colors or names to match what's in the Finder preferences. Maybe the permutation of the indices is fixed, but I'd be more comfortable if the permutation were documented.

— F

Seth Willits

unread,
Apr 1, 2012, 8:25:31 PM4/1/12
to cocoa-dev@lists.apple.com List
On Apr 1, 2012, at 10:33 AM, Fritz Anderson wrote:

>> Why wouldn't it be? Just display them in the same order as Finder and don't rely on the display index being the same as the label index you use in the assignment. I don't really see the problem. (I've done this.)
>
> Hard-coding the order works in practice — most of the time. Unless I much mistake, it doesn't work in principle. Users can change colors and label names, and I know of no way to sort colors or names to match what's in the Finder preferences. Maybe the permutation of the indices is fixed, but I'd be more comfortable if the permutation were documented.

Users cannot change the Finder label colors, only the label names.

Though, I was wrong; My code actually is relying on pre-10.6 path FSSetCatalogInfo to set the file label. Oops. :)

But as you say, in practice it'll work. The order doesn't make any sense to me either, but the label names and colors don't change their index in 10.7 or 10.6 so you can rely on it. I doubt they've changed for 10.8 either.


--
Seth Willits

Reply all
Reply to author
Forward
0 new messages