I was using AVRDUDE command line instructions to program a leonardo via its bootloader. Initially it had me stumped until someone pointed out that the com port ennumerated under the Windows device manager changes com number while in bootloader mode. (I.e. it briefly exists as a different com port number when in bootloader mode for about 8 seconds after reset or power up - or after a 1200 baud connect and disconnect happens).
So when I reset the board -I noted this 'temporary' com number to use in the command line.
Once I'd edited this correct (boot mode) com number in the command line, all was well. In the arduino IDE, the com port selected by the user during setup is the one which ennumerates after the leonardo has been powered up for more than 8 seconds and has 'settled' - this is the port number which is shown bottom right in the IDE.
So my question is - how does the IDE know which com port to use during the downloading via bootloader? I'd like to look at doing an app at some point that downloads code to the device and I presume the IDE authors were faced with the same challenge.