#!/bin/zsh getid() { xinput list | grep -m 1 "$1" | sed 's/.*=\([^\t]*\).*/\1/' } MOUSEID1=$(getid "TPPS/2 IBM TrackPoint") if [ -z "$(xinput list | grep '2ndMouse')" ]; then xinput create-master 2ndMouse SECOND=$(getid 2ndMouse) xinput reattach $MOUSEID1 $SECOND else FIRST=$(getid "Virtual core pointer") SECOND=$(getid 2ndMouse) xinput reattach $MOUSEID1 $FIRST xinput remove-master $SECOND fi