Mac os x dock position

Any ideas how to create a touchbar macro that, when pressed, moves the OSX dock position from the bottom of the screen to the right side, then when press the action is reverted? (Or even better, a USB C cable is connected for an external monitor, this triggers the macro to happen).
I have my laptop beneath my external monitor (I use its keyboard to type), hence having to move the dock placement when it's connected.