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) )

How do I need to modify the script if I want to target the html instead of the text field? The reason I need the html is so I can set up some truncation via ellipses which, to my knowledge, is not available for text elements.

instead of "textString" use "embedHTML" (see List of Properties in the documentation.

I was looking around on those pages but never found it. THANKS!