You can check for when you get the mounted error and then dismount. But this addon is already made for you:
https://www.wowinterface.com/downloa...oDismount.html
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff,
The Tao of Pooh