To manually control the enabled state of a menu items the menu that contains it must disable automatic enabling of its items
Menus can turn off automatic enabling in one of two ways:
menu.autoenablesItems = false
Once the menu is menu is no longer enabling and disabling menu items the menu items can be programmatically set in one of two ways
menuItem.enabled = true
Menu items can be automatically enabled by connecting menu items actions to the first responder and implementing the delivered action on an object in the responder chain as described by Apple's docs.