This is something really simple that I think should be part of the base UI, but instead, we have 3 bindings pertaining to nameplates that I think could be turned into one. Or at least be added as an extra binding. Just thought I'd share it in case anyone wanted to turn it into an addon or include it in their UI compilations or w/e.
This works in combat unlike the /run macros that are passed around as an answer to this fairly common question.
Lua Code:
local PlateCycle = CreateFrame("Button", "NameplateCycle", nil, "SecureActionButtonTemplate, SecureHandlerBaseTemplate")
PlateCycle:SetAttribute("type", "macro")
PlateCycle:Execute([[
Scripts = newtable()
Scripts[1] = "/click InterfaceOptionsNamesPanelUnitNameplatesEnemies"
Scripts[2] = "/click InterfaceOptionsNamesPanelUnitNameplatesFriends"
]])
PlateCycle:WrapScript(PlateCycle, "PreClick", [[
Index = Index == 1 and 2 or 1
self:SetAttribute("macrotext", Scripts[Index])
]])
Code:
<Binding name="CLICK NameplateCycle:LeftButton" category="Your addon" />