I checked around online and followed the basic steps for populating a popup button from a list. That appears to work smoothly, and when I click on the popup the items are listed properly.
However, I can’t select them…when I try I get the following runtime error:
Exception raised during posting of notification. Ignored. exception: Invalid parameter not satisfying: (index >= 0) && (index < (_itemArray ? CFArrayGetCount(_itemArray) : 0))
Did I miss a something somewhere? THANKS!
(here is the code…)
on addPopupItem(theItem, thePopup)
make new menu item at the end of menu items of menu of thePopup with properties {title:theItem, enabled:true}
end addPopupItem
tell application "iTunes"
set thePlaylists to playlists as list
repeat with thePlaylist in thePlaylists
try
if smart of thePlaylist is equal to false then
my addPopupItem(name of thePlaylist, thePopup)
end if
end try
end repeat
end tell
I’m with T.J. If your error is coming when you try to select the items, then your problem is not in the code which creates the menu, but rather in the ‘choose menu item’ code that evaluates the selected menu item. Are you evaluating the item based on it’s title, name, or tag? What I usually do with popup buttons, is attach the ‘choose menu item’ handler to the menu itself. If you attach it to the menu items themselves, items created programmatically will not be attached to anything, unless you attach them to a script.
on choose menu item theObject --> Attached to the MENU, not it's items
set theMenuItemTitle to title of current menu item of theObject
set theMenuItemName to name of current menu item of theObject
if theMenuItemName is not "Default" then
display dialog (theMenuItemTitle as string)
end if
end choose menu item
on addPopupItem(theItem, theName, thePopup)
make new menu item at the end of menu items of menu of thePopup with properties {title:theItem,name:theName, enabled:true}
end addPopupItem
Also, if you’re using a ‘pulldown’ menu, make sure that there is more than one item in the menu. If at any point you clear the menu by ‘deleting every item’ and then rebuild it, make sure it’s got at least one menu item for a title, and then some menu items to actually select.
Post your choose menu item handler, too. Hope that get’s you started, let us know what you find.
j
I actually didn’t have it connected to any applescript handler at all. At a later point in my code I simply reference the title of the selected menu item.
I tried adding the choose menu item handler, and left the handler emtpy, but that didn’t change anything at all. Any other ideas?
EDIT-----------------------
Also, placing a log statement alone in the choose menu item handler indicates that the error happens BEFORE that code is run, since it is never logged.
Also, this part of the error (which actually comes first) I missed before…
*** Assertion failure in -[NSMenu itemAtIndex:], Menus.subproj/NSMenu.m:638
It’s clearly an error in the Obj C code, but what have I done wrong to cause it?
Perhaps this is similar to what you mentioned about the pulldown, but my menu still did have 6 items in it. Even so, if I don’t delete what’s there everything works wonderfully.
This is OK for now, since all that is there is a default “None Selected” item at startup. But what if I wanted to repopulate it during runtime? Any ideas why that line of code messes stuff up?
Thanks so much for your help, guys. I appreciate the tips!