9

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?

mxmln
  • 91
  • 2

3 Answers3

2

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.

Valentin Shergin
  • 7,166
  • 2
  • 50
  • 53
1

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.

Abhi Beckert
  • 32,787
  • 12
  • 83
  • 110
0

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

thomasfuchs
  • 5,386
  • 2
  • 18
  • 38