Simulated click of a popup menu

Is there a (reliable) way to programmatically click a popup menu? (Besides UI scripting System Events of course). I’ll describe what I want and why:

I have a table where one of its cells has a popup menu (NSpopUpButtonCell). A newly added row of the table will have none of the popup menu items selected, so it displays as “No Value” (and that is intentionally so by design).

A row is validated by ‘controlTextDidEndEditing’ (after the user has edited another cell), and if the popup menu is still not set to a value, I raise an alert sheet. After closing the sheet, it would be nice if the popup menu could be highlighted as if the user had clicked the menu so the alternatives are shown – that would be a nice and direct way of encouraging the user to select a value.

Can this be done in an easy way?

/Harald

Yes, there is. If your popup button was called thePopup, then you would just add the line:

thePopup’s performClick_(me) inside your method that evaluates the result of your alert sheet.

Ric

Thanks for response! It looks like the perfect thing, but I can’t make it happen though.

‘performClick:’ is a method of NSButtonCell, and NSpopUpButtonCell (which is what I have) inherits from NSButtonCell, so it should work.

If I create a NSpopUpButton for test purposes and put that on the window (not inside the table) and bind it to thePopup, it works excellent. However, if I instead bind its child, NSpopUpButtonCell, to thePopup, it does not work (and no error messages).

Since what I have in the table is NSpopUpButtonCell (must be because a NSpopUpButton cannot be put into a table) I have a problem. So the question now is if there is a way around that?

Sorry, I don’t think I can figure that one out.

Ric

Actually, I did figure it out. Use “theTable’s performClickOnCellAtColumn_row_(0, 0)” where “theTable” is the outlet for the NSTableView.

Great, it works!
Thank you Ric!