NSStatusItem text length

If an NSStatusItem’s text length becomes too large, OS X displays nothing for that NSStatusItem. So, for example, on a small screen you might be able to have an NSStatusItem with 29 characters and it will fit fine. But add, say, one more character and the whole thing disappears.

This isn’t a Xojo thing or a MacOSLib thing etc, it happens in Objective-C apps too. It stems from the fact that OS X doesn’t provide feedback when an NSStatusItem’s text is too long, so you can’t react to it by truncating the text etc. Furthermore, you can’t know what other application the user is going to be using, so you don’t have any idea of how many menus are being shown in the menu bar (thus you have no idea of the free space).

Does anyone have any ideas for strategies to deal with this problem?

you could maybe put a NSWindow Delegate (e.g. via NSWindowDelegateMBS class in our plugins) on the window of the NSStatusitem.
This way you could maybe get an event if it’s hidden.

There are at least 3 feature requests into Apple about this that I’m aware of. Mine is 9885228 (not that you can view it).

bug reports with Apple are either not yet reviewed or duplicate for me. :frowning:

And some complain about the Xojo team’s Feedback record. Mine RADAR entry is from August of 2011…

[quote=109677:@Christian Schmitz]you could maybe put a NSWindow Delegate (e.g. via NSWindowDelegateMBS class in our plugins) on the window of the NSStatusitem.
This way you could maybe get an event if it’s hidden.[/quote]
It’s mostly a window-less app though.

I guess you haven’t found any workarounds? I think it would be a possible with non-public APIs but that’s no good for the MAS.

The Statusitem is a window…

Ha that ones real new
We filed one recently that was marked as a duplicate of one from 1996 or 1997 :slight_smile:

I’m not sure what you mean. NSStatusItem inherits from NSObject, it’s the menu extra in the menubar - how is it an NSWindow?

NSStatusItemMBS has a property window to get the NSWindowMBS object.
I know it’s there, because I coded that years ago.

Okay, in my testing, the window stays visible even if status item is not visible.

Maybe AppleScript can check the status like it does for menu items ? The difficulty is to know the name of the item, but it is not a problem as you are creating it.

This actually might be a great idea. I suspect that AppleScript won’t be able to refer to the statusitem when it isn’t visible (under the conditions mentioned) but I could use a repeating Timer and when the script returns an error, I’ll know it hasn’t been able to talk to the menu and it’s therefore too long. I could even start truncating the text until the script can talk to the menu again, then I’ll know it fits. I hope to try this soon, thanks Michel.