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.
[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.
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.