1570s, "aptly, suitably, at the right time," perhaps from pat (adj.) in sense of "that which hits the mark," a special use from pat (n.) in the sense of "a hitting" of the mark. The modern adjective meaning "that is exactly to the purpose, suitable for the occasion" is 1630s, from the adverb.