Are you physically moving waveguides to align to a connector? Maybe you are tuning a set screw. Do you have a mechanical device to do the alignment (stepper motor or something)? Do you have a meter to measure the power out? You could have a loop take the reading, step the motor in one direction. If higher output, continue stepping until power goes down. If lower, step in opposite direction. If this is not what you want, be more specific.