title: How to update a menu item in a status menu on Objective-C
body: <p>I'm a very beginner in Objective-C and in Mac development. I've searched this site for the answer I'm seeking, but due to a big ignorance I could not understand how this should be done.</p>
  
  <p>The following piece of code implements a menu in Mac status bar, near the battery, wifi, etc icons on the top right of the screen.</p>
  
  <p>If the user disconnects a device from the computer the method <code>sayAdapterIsConnected</code> is called with one boolean argument. Depending on that argument, one of the menu items, in this case the <code>enabledOption</code>, should get disabled. I mean, the menu item should be enabled or disabled.</p>
  
  <p>This works only if the menu is closed. If the <code>statusMenu</code> is opened, it is not updated.</p>
  
  <p>I know there is a way to update an open <code>statusItem</code> menu. Wifi status icon updates its networks while the menu is open.</p>
  
  <pre><code>@interface ENHeringAppDelegate : NSObject &lt;NSApplicationDelegate&gt; {
      NSStatusItem * statusItem;
  }
  
  @property (weak) IBOutlet NSMenu *statusMenu;
  @property (weak) IBOutlet NSMenuItem *enabledOption;
  
  @end
  
  @implementation ENHeringAppDelegate
  
  - (void) awakeFromNib {
      statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
      [statusItem setMenu:_statusMenu];
      [statusItem setTitle:@"TEST"];
      [statusItem setHighlightMode:YES];
  }
  
  - (void)sayAdapterIsConnected:(bool)connected {
      if (connected)
          [self.enabledOption setEnabled:true];
      else
          [self.enabledOption setEnabled:false];
  }
  
  @end
  </code></pre>