setting the current menu item

i’m trying to set the current menu item of a popu button, i’v tried everything here and i just get a -10006 error (i think thats what it was)

Post the code that’s causing the error.

    tell window "prefs"
        tell popup button "default"
            set current menu item to (first menu item whose title is defaultTeam)
        end tell
    end tell

thats in an on will open handler for a panel.

heres the error i get

Can't set «class menI» 1 of «class popB» "default" of window "prefs" whose title = "" to «class menI» 1 of «class popB» "default" of window "prefs" whose title of it = "". (-10006)

ok, i think i found the problem. the defaults were being read wrong, so it was looking for a menu item with the title “” so i think i fixed it, if i have anymore problems i’ll post them here. thanks.

now i’m getting this error

Can't make «class cuMI» of «class menE» of «class popB» "defaultTeam" of window "prefs" into type reference. (-1700)

I am having the same problems on a similar project. I can’t figure out how to select a particular item with out having the item number. I believe counting the rows would help, although I am unable to do that either.


Er, «class cuMI» of «class menE» is current menu item of menu

ok, how do i get the index number of the current menu item?

That code works fine for me. Your error includes current menu item of menu; That code does not appear in the code you posted.

yeah i know, the code i posted is what i have now, i accidentally gave you an old error, from when i tried adding “of menu”. Ok heres some background info on whats going on. The title of the menu item is called from the user defaults, that wasnt working before, now it is, so in the error i see the name of the menu item i want to set it to. But see the problem is that the popup button is populated in a on launched handler, and the defaults are read and set in the GUI on a on will finished launching handler, so maybe its trying to set the current menu item before the menu is populated.


I’ve played around with your problem using my own program that has the same popup button to choose menu items.

These are what I found that work and do not work:

  1. Setting the current menu item to any item you want via script does not work in the tests that I made. It might but as far as my tests show, it does not. I also get the same error as you did. When the window that contains the popup button opens, the first item on the menu list is always set to whatever you used the first time you populated the popup button (via the “make menu item…”).

  2. In order to set the menu item to the one that you want, you will have to define that item before you populate your popup button. For instance, in my case (where I use the popup button to contain a menu list of iTunes playlists) I had to define the playlist that I want to be the default everytime my main window with the popup button opens, then make that playlist my current playlist. Then, I create the first item in the menu list of the popup button with the “make menu…” command. After that is done, I then follow it up with the rest of the items that populate my popup button.

  3. So that your menu list is not duplicated, ie., your current menu item is not duplicated, make sure to exclude it when you populate the rest of the items in the menu list.

When I did the above in my application, I could create a popup button with the menu list always starting with the default menu item as the current menu item.

I hope this gives you some ideas.

Good luck.

archseed :slight_smile:

thanks, i fixed it, apparently a will finished lauching handler is called before the on launched handler

That’s correct.

thanks, thats all good to know.

Thanks Bruce.

Now, I can try to fix a problem in my application that needs to build set something first before the nib wakes up.


archseed :slight_smile: