I don't know exactly how it works. Anyway, I've ended up with the following, which serves me to my satisfaction.
- (void)showStatus {
for (NSInteger i4 = 0; i4 < alertArray4.count; i4++) {
...
NSString *num4 = [NSString stringWithFormat:@"%li",(long)i4];
NSString *menuTitle = [NSString stringWithFormat:@"%@ in %@ days",person,nextDOB];
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(statusItemClicked:) keyEquivalent:@""];
[menuItem setTarget:self];
[menuItem setRepresentedObject:num4];
}
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
statusImage = [NSImage imageNamed:@"appIcon16"];
[statusItem setImage:statusImage];
[statusItem setMenu:statusMenu];
[statusItem setTitle:alertCount.stringValue];
}
- (void)statusItemClicked:(id)sender {
id selectedItem = [sender representedObject];
NSLog(@"%@",selectedItem);
}