Popup menu best practise?

What is the best practise for popup-menus I wonder? I currently need to give the actual menu entry the same number of states as I have menu items. Not very elegant and kind of high maintenance. I admit, my menu is a little more complicated because it needs to convert to macOS Aqua, macOS dark and Windows but that is not relevant for the question. Is there a script that someone has done that I might be able to reuse that will set the popup menu’s entry to whatever is in the text (or, html) field of the last left-clicked menu-item? Without the need for an extra state for each menu item?


Menu.atype.zip (2.5 MB)

Thanks for any help!

This is how I build these kind of controls. I use Javascript to display the selected value.

Select.zip (341.6 KB)

1 Like

That is exactly what I needed to know. I think I am (slowly) getting the hang of it. This is so much more elegant.
This works, thank you!

The next thing I need to find out is how to apply this script to the icon before the menu item but I will try before I ask. :slight_smile:

So if I see this right, for an image fill to be used instead of a text, I need to replace the
“textString” and text parts with the image parts, is that correct?
states.forEach( s => at.cellSetPropertyInState(cell, "textString", text, s)

Found it :slight_smile:

let activeState = targetCells[1].activeStateIdentifier
let image = targetCells[1].valueForKeyInStateWithIdentifier("backgroundImageResource", activeState)

let cell = targetCells[0]
let states = cell.widget.states

states.forEach( s => at.cellSetPropertyInState(cell, "backgroundImageResource", image, s) )