I want to perform the action which is bound to a NSMenuItem, I'm developing a plugin for osx app. Therefore I don't know target method of the menuitem. (target of the menu item returns nil)
How can I press NSMenuItem programmatically ?
When the target of a menu item is nil, that means it targets the responder chain. It's the same as if the menu were connected to the First Responder placeholder in the NIB.
Whether the target is nil or a specific object, it is dispatched the same way:
[NSApp sendAction:theSelector to:theTarget from:theSender];
So, with a menu item, that would be:
[NSApp sendAction:menuItem.action to:menuItem.target from:menuItem];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With