mxmln
mxmln

Reputation: 91

Is it possible to add a NSStatusItem to a specific position in NSStatusBar?

I use self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength]; to add an statusItem to the systemStatusBar on OSX. The statusItem then appears on the left-most position in the systemStatusBar. I was wondering if there is a way to add such an item to a specific index e.g. on the left side of the system clock?

Upvotes: 9

Views: 1149

Answers (3)

Valentin Shergin
Valentin Shergin

Reputation: 7344

Yes and no. Using private API you can specify priority for adding NSStatusItem. I have developed a tiny category for NSStatusBar (NSStatusBar+MISSINGOrder) witch provides simple method for this:

NSStatusItem *statusItem =
    [systemStatusBar statusItemWithLength:NSVariableStatusItemLength
                               positioned:NSStatusBarItemOrderingModeAfter
                               relativeTo:NSStatusBarItemPriorityNotificationCenter];

You can look inside for implementation details.

Upvotes: 2

Abhi Beckert
Abhi Beckert

Reputation: 33369

There is a private API to do this:

NSStatusItem *item = [NSStatusBar _statusItemWithLength:NSSquareStatusItemLength  withPriority:INT32_MAX];

That will place the status item all the way to the right (or at least, as far to the right as you're allowed to have them. It's still to the left of spotlight).

Obviously being a private API you should wrap it in a responseToSelector if statement.

Upvotes: 1

thomasfuchs
thomasfuchs

Reputation: 1

No. Apple does not provide an API to choose the position.

Upvotes: 0

Related Questions