If /dismount doesnt work, try /cancelaura (mount name).
The last part of your macro “and then cast a spell” won’t work because switching forms activates the GCD.
So you could do:
/cancelaura Mount Name
/cancelaura Cat Form
/cancelaura Bear Form
/cast Moonkin Form
This will put you into Moonkin Form, regardless of your current form or mount state. It satisfies the criteria of being spammable because of the aforementioned GCD on changing forms. But if you click it again after the GCD is over, it will cancel your Moonkin Form.