Programmatically show NSPopUpButton menu?

  • Hello,

    I would like to bring up the menu of an NSPopUpButton programmatically - ie. without the user having to click on the button itself. This may sound strange, but the popup button's menu controls different formatting aspects of a text view. The user brings up the menu and then hits a keyboard shortcut connected to the menu items in the popup button to change the formatting (the keyboard shortcuts are just single keys - "1", "2" etc - so the menu has to be presented before the user can use the shortcuts; my app has a gazillion keyboard shortcuts so this was the best way of doing this part).

    I tried this:

    - (void)showElementsMenu:(id)sender
    {
        [[elementsPopup cell] attachPopUpWithFrame:[elementsPopup frame] inView:elementsPopup];
    }

    But to no avail - the popup button's menu does not get brought up.

    Does anybody know how to do this?

    Thanks in advance!
    Keith
  • on 06/10/26 16:46, Keith Blount at <keithblount...> wrote:

    > I would like to bring up the menu of an NSPopUpButton programmatically - ie.
    > without the user having to click on the button itself. This may sound strange,

    I was thinking of doing the same thing, but for a main menu.  I haven't
    gotten around to trying it yet, but I read in the list archives that, in
    general, to make simulated mouse clicks, you find the (x,y) location of the
    control you want to click, and then feed this location to
    CGEventCreateMouseEvent.  Give it a try and let me know if it works!
  • On Thu, 26 Oct 2006 13:46:46 -0700 (PDT), Keith Blount
    <keithblount...> said:

    > I would like to bring up the menu of an NSPopUpButton programmatically

    And performClick: isn't working? m.

    --
    matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
    A fool + a tool + an autorelease pool = cool!
    AppleScript: the Definitive Guide - Second Edition!
    <http://www.amazon.com/gp/product/0596102119>
  • D'oh!

    Thanks Matt, I knew I must be missing something obvious - and I was.

    Thanks again and all the best,
    Keith

    ----- Original Message ----
    From: Matt Neuburg <matt...>
    To: Keith Blount <keithblount...>
    Cc: <cocoa-dev...>
    Sent: Friday, October 27, 2006 2:16:50 AM
    Subject: Re: Programmatically show NSPopUpButton menu?

    On Thu, 26 Oct 2006 13:46:46 -0700 (PDT), Keith Blount
    <keithblount...> said:

    > I would like to bring up the menu of an NSPopUpButton programmatically

    And performClick: isn't working? m.

    --
    matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
    A fool + a tool + an autorelease pool = cool!
    AppleScript: the Definitive Guide - Second Edition!
    <http://www.amazon.com/gp/product/0596102119>
  • Am 27.10.2006 um 00:06 schrieb Jerry Krinock:
    > on 06/10/26 16:46, Keith Blount at <keithblount...> wrote:
    >> I would like to bring up the menu of an NSPopUpButton
    >> programmatically - ie.
    >> without the user having to click on the button itself. This may
    >> sound strange,
    >
    > I was thinking of doing the same thing, but for a main menu.  I
    > haven't
    > gotten around to trying it yet, but I read in the list archives
    > that, in
    > general, to make simulated mouse clicks, you find the (x,y)
    > location of the
    > control you want to click, and then feed this location to
    > CGEventCreateMouseEvent.  Give it a try and let me know if it works!

      While you're at it, make sure you also test it in cases where the
    thing to be clicked is covered by another window, or the application
    is hidden. Wouldn't want to accidentally hit the "yes" button of a
    "really empty trash" panel that's on the screen.

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today