How to make xinput commands permanent

Here's my final solution, I corrected an extremely unlikely and non critical race condition in Nir's answer. Also I handle the fact that I can't remap the keys when the mouse is unplugged (no error messages while it's unplugged).

I added to ~/.xinitrc:

# Map mouse button 8 (top right) to button 2 (top left) and vice versa, run when changes to the mouse occur
while true; do
  NEW_MOUSEID=$(xinput | grep "Expert Mouse" | grep -o -E '[0-9]+' | head -n 1)
    if [ "$MOUSEID" != "$NEW_MOUSEID" ]; then
      MOUSEID=$NEW_MOUSEID
      if [ "$MOUSEID" != "" ]; then
        xinput --set-button-map $MOUSEID 1 8 3 4 5 6 7 2 9 10 11 12
      fi
  fi
  sleep 2
done &

I used the mouse ID parsed from xinput as the trigger instead of lsusb, but it's has the same effect.

Note that the pipes after the xinput command just parses the ID of the mouse, which can change. The extra NEW/OLD mouse ID's were an anal avoidance of any possibility of a race condition.

Thanks @Nir for the suggestion.