Referring to popup menu items by sequence instead of title

Hi all,

I’m trying to build a popup button from a dynamic list of urls and titles for those urls separated by a space. What I’m doing is setting variables for the urls by position, then building a popup button of the descriptions. What I can’t seem to figure out after scouring these forums is how to refer to the popup button items by position (number) from top to bottom rather than by title.

Here’s what I’m trying to do:

if theObject is popup button "urls" of tab view item "links" of tab view "tabs" of window "main" then
		if the in number of the current menu item of theObject is 0 then
					open location url1
		else if the number of the current menu item of theObject is 1 then
					open location url2
		end if
	end if

It’s not working, I’ve tried using “tag” but it seems all the items have tag #0. I’ve tried “index” but that doesn’t work either. Any suggestions?

This is straight from the reference manual:

Access: read/write
Class: integer
the tag of the menu item (an arbitrary item associated with the menu item);
default is 0; you can set this property in the Info window in Interface Builder; you
might use a tag, for example, as a way to identify a particular menu item

Did you try to set it?

OK, that’s a good suggestion, but please remember that this is a dynamic list, it can change at any time, so how would I set a tag of a popup button item if I can’t be sure what the title is going to be? Therein lies the problem. How would I st the tag integer unless I started with x amount of blank items to begin with, which is problematic as they need to be blown away when populating the popup button anyway. If I can’t address the items by number or name, I’m not going to be able to set the tag either…

what I really need is a way to talk to the popup button and its items/titles by sequence…

first, second, third, fourth or


I don’t know if I’m getting what you’re saying now. Here’s an example of using the tag to index menu items:

property the_list : {“”, “”, “”}

on clicked theObject
tell menu of popup button “popup” of window “main”
if name of theObject is “set” then
delete every menu item
set the_tag to 0
repeat with this_item in the_list
set the_tag to the_tag + 1
make new menu item at end of menu items with properties {title:this_item, enabled:true, tag:the_tag}
end repeat
else if name of theObject is “get” then
set tag_list to tag of every menu item
log tag_list
end if
end tell
end clicked

on choose menu item theObject
set cur_item to current menu item of theObject
set the_index to tag of cur_item
open location (item the_index of the_list)
end choose menu item

There’s two buttons “set” and “get” connected to the clicked handler. When the user hits the “set” button, it deletes the old items and adds the list of new urls each with a tag 1, 2, and 3 in this case. When the user clicks the “get” button it logs the tags. When the user selects a url from the pop up, the default browser opens that url.

If this is not what you’re talking about, then disregard.

Editted: and I forgot to say, the ‘choose menu item’ handler is connected to the popup button.



this is exactly what I needed with one small exception. How do I start the index from 0 or 1 or 2 or 3 in case I want a “header” in the popup button that labels it “links”?

This is what I did, and it works just fine, with one small exception:

if theObject is popup button "links" of tab view item "urls" of tab view "tabs" of window "mail" then
		set oy to (contents of popup button "links" of tab view item "urls" of tab view "tabs" of window "mail") + 1
		open location item oy of {url0,url1,url2,url3,url4,url5}
   end try
end if