I have been banging my head with this for 3 hours…
It populates the popup button, and once I try to pick an item it simply greys out the entire list and selected item.
I push this code to a new project and it works…
Any clues?
tell application "Mail"
set allAccountAddresses to email addresses of accounts
end tell
set list_of_sender_addresses to {} -- start with an empty list
repeat with i from 1 to count of allAccountAddresses
set theAccount to item i of allAccountAddresses
if (count of item in theAccount) = 1 then
set end of list_of_sender_addresses to item 1 of theAccount
else
repeat with eachEmail from 1 to count of item in theAccount
set end of list_of_sender_addresses to item eachEmail of theAccount
end repeat
end if
end repeat
(**** somehow I need to reset the popup button, before running this: ****)
tell theDropDown's |menu|() to removeAllItems()
repeat with i from 1 to the count of items in list_of_sender_addresses
tell theDropDown's |menu|() to addItemWithTitle_action_keyEquivalent_(item i of list_of_sender_addresses,"emailSelected:" , i as text)
end repeat
on emailSelected_(sender)
log (theDropDown's title)
end emailSelected_
What do you mean by this? It works if you put this code in a new project? I put it in a new project, and it worked fine, so what’s the problem? We can’t help find a problem if it’s not in the code you posted. You must have done something wrong originally that you fixed.
Sorry, I don’t see anything wrong with the code you posted – I can’t see why your menu items are added but not enabled. I can’t recreate that problem here. Possibly, it has something to do with Xcode 4 – I’m still using 3.2.6, so I can’t help with that.
There is nothing strange about that – it’s not an ID, it’s an index, and indexes in cocoa are always 0 based (or at least mostly 0 based, I can’t think of any 1 based indexes at the moment).
The previous method that you were using, addItemWithTitle_action_keyEquivalent_, doesn’t have any index, so it wasn’t asking for you to start at 1 – you started at 1 in your repeat loop because you were using an applescript list which is 1 based, rather than a cocoa array which would be 0 based.