You cannot get all items as NSStatusItem
objects because they don't all belong to your process.
If you're only interested where they are on screen and which apps own them, you can do that with the CGWindow
APIs, because technically the status items are (borderless) windows. Here's an example that logs information about all status bar items:
NSArray *windowInfos = (NSArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
for (NSDictionary *windowInfo in windowInfos) {
if (([[windowInfo objectForKey:(id)kCGWindowLayer] intValue] == 25)
&& (![[windowInfo objectForKey:(id)kCGWindowOwnerName] isEqual:@"SystemUIServer"])) {
NSLog(@"Status bar item: %@", windowInfo);
}
}
[windowInfos release];
Note that the system's items are not included; they are all combined in one window that belongs to "SystemUIServer". Also, this method might not be particularly reliable because the window layer for status bar items might change (it's assumed to be 25 here, but this is not documented anywhere).