Change the NSPopover's behavior property to NSPopoverBehaviorTransient.
NSPopoverBehaviorTransient
The system will close the popover when the user interacts with a user interface element outside the popover.
Note that interacting with menus or panels that become key only when needed will not cause a transient popover to close. The exact interactions that will cause transient popovers to close are not specified.