How does Mac gather printer information (mainly driver) after a printer is selected in the list of printers to add? When we want to add a printer to mac, we go to "Printers and Scanners" in system preferences. There we click on "+" button and click on "Add Printer or Scanner". In new dialog with title "Add", we see a list of printers.

When we select one of the printer: printer-x, we see status: "Gathering printer information...". And its driver is automatically selected. How is Mac gathering printer information? What is this whole process of adding a printer in details? Is there any tutorial/article that can help? I have tried google search, could not find something of good interest yet.

I want to debug a situation where Mac is choosing driver for a printer sometime and sometimes it does not (for the same printer). Expected driver to see there is AirPrint. The printer is being added from a print server. So, want to have a look at what is happening in the background.
After carefully looking at the DNSCache and Network:

More details on dns-sd.org however in short, for everything to work correctly, following four DNS Records for each printer are needed on client side in case of airprint/secure airprint:


PTR record of type _universal._sub._ipp/ipps._tcp  (lets call it universal): needed only if printer is airprint compatible (see dns-sd.org)
PTR record of type _ipp/ipps._tcp (lets call it ipps)
SRV record
TXT record


SRV record tells about the service related data (server/port etc.) and TXT record tells about the printer capabilities.

On Mac, "ipps" and "universal" records are queried by different processes (printtool and PKBrowserServic respectively). From observation: Queries of "universal" records by PKBrowserServic are more frequent than queries of "ipps" records by printtool. So, in a scenario: it has universal records but not ipps, it won't identify the driver. 

To answer the original question: when a printer is selected, it queries for SRV and TXT record (based on universal or ipps records which are in cache already, thats how we see the printer in the list). If printer/print server is not available or if ipps record is missing, mac won't be able to do 'Auto Select' for the driver.

This problem can be fixed in multicast by self-querying both universal and ipps before TTL of the records expire so that the caches of all mac clients are updated.

In case of unicast, mac has high TTL of universal/ipps records, so it might take some time for ipps record to be updated in the cache in a new network but in few minutes (max 10 mins from observation), it has both ipps and universal and the issue does not exist anymore.
Another way to handle it quickly is to clear cache (sierra: killall -HUP mDNSResponder)