Ok so youve got a scrijob monitoring selection change then baseed on tool swithhes whats manipulated.
Dont do this its a bit tacky. Its one of those things everyone does just to abandon later. WHat you would be 99% of animators realy liking is adding 3 channels to the child (better one) that are linked to the parent just driven from its ancestor.
Fisrtof everyone can acces the parent manualy WITHOUT being able to se it, yes even stupid animators know this, namely thet you can traverse the hierachy with arrow keys. (Its porbably VERY common for them since they traverse bones thsiway far more than most riggers ever do)
But just in case you will have to bash your head here
Secondly you can use the show manipulator tool here easily... because every shape can specify what obejct is actualy manipulated wich does not need to be it.
3rd if you do need this use
undoInfo -stateWithoutFlush 0; //at the beginning of yourscriptjob
undoInfo -stateWithoutFlush 1; //at end