Hans, your code is indeed somewhat cumbersome and strange, and you probably do not even need Lisp to achieve what you want.
1.
But if you want to use Lisp, something like this will do the trick:
(setvar 'osmode (boole 6 (getvar 'osmode) 1))
This will toggle the Endpoint osnap.
2.
It is however easier to change the command in the CUI.
If the command is "_endpoint" and the macro is used while a command is active, the Endpoint snap will be set as a temporary override (this is the default in BricsCAD).
If the command is "'_endpoint" (with an apostrophe) the Endpoint snap will be toggled even if a command is active (and this seems to be the behavior you want).
3.
The depressed state of the buttons is controlled by the CUI. See the 'State' line in the code below. I assume that AutoCAD also supports this.
<ToolbarButton>
<Name>Snap to Endpoint</Name>
<MenuItem>
<MacroRef MenuMacroID="osnap_endpoint"/>
</MenuItem>
<State>$(if,$(=,$(and,$(getvar,OSMODE),0x0001),0),,!.)</State>
</ToolbarButton>