That's because the old
GetCVar() function either returns a string or
nil. There are Lua functions provided in the default UI that are run by the keybind system for toggling music and sound. Using the default keybindings, you can use Ctrl+M and Ctrl+S for music and sound respectively. To do this in a macro, you make calls to
Sound_ToggleMusic() and/or
Sound_ToggleSound(). Both are defined in Sound.lua within the FrameXML.
Toggle Music:
Code:
/run Sound_ToggleMusic();
Toggle Sound:
Code:
/run Sound_ToggleSound();