# How do I dynamically update “name” of Action Menu?

I have created an action menu that allows you to change the style of a cell. It works. However, I would like it to dynamically update the action menu "name". I can't get the name to refresh. Anyone have any ideas? Here is my code.

ActionMenu[
Dynamic[CurrentValue[Cell, "CellStyleName"]]
,
Evaluate[
# :> FrontEndTokenExecute[InputNotebook[], "Style", #] & /@ {
"Subtitle", "Section", "Text", "Input", "Subsection",
"DisplayFormula", "DisplayFormulaNumbered"
}
],
]

• It's not only about refreshing, it's a problem of getting CurrentValue[Cell, "CellStyleName"] from the Cell you really want it. E.g. when you ust this to change the style of the cell that ActionMenu is in, it will update. – Kuba Oct 8 '15 at 9:24
• I see. To further clarify... I am attempting to replicate the functionality built into Mathematica. When one clicks on the format menu and then hovers over Style, you can see that the correct style is checked for the current cell in the notebook. – Michael McCain Oct 8 '15 at 9:28
• I think I see what you are saying. – Michael McCain Oct 8 '15 at 9:32
• I wondered how formatting toolbar menu is done and I've not found any sources in Installation directory. Maybe it's not easy/possible to this in pure Mathematica, at least in efficient way. You can always put UpdateInterval and check SelectedCells[] styles but this isn't neat for me. – Kuba Oct 8 '15 at 9:38
• I see. I'll mess around with this some more and see if I can get anything to work. It seems I am looking for a function that replicated InputNotebook[] but at the cell level. Something like InputCell[] but this doesn't exist. Thank you for edit. – Michael McCain Oct 8 '15 at 9:41

After a couple hours of tinkering around... I think I got it. Here it is...

currentStyle =
DynamicModule[{label = "         "},
Dynamic[With[{sel = Cells[NotebookSelection[InputNotebook[]]]},
If[sel =!= {},
label = CurrentValue[sel[[1]], "CellStyleName"]]];
label, UpdateInterval -> .5]];


• Let me then leave the comment about Dynamics here: Quick general tip for DockedCells. I'd not put there crucial Dynamic info, like Dynamic @ CurrentValue[something]. They are not trustworthy (Dynamics) in case of Kernel crash: Dynamic cells after Kernel restart/quit:. – Kuba Oct 8 '15 at 12:25