Townley was born in Waukesha, Wisconsin to Reverend Robert Townley and his wife Mary Wilkinson. After the equivalent of a high school education, he gained a job as a clerk in the local town bank. A year and a half later he was admitted to the University of Wisconsin–Madison. He would graduate four years later with distinction, and become a member of Phi Beta Kappa.
During his second year at the university he took a course in astronomy. He was also given a room at the Washburn Observatory and worked nights as an assistant. These would serve to shape his interest in astronomy.
In his second year as a graduate student he was offered a Hearst fellowship at the Lick Observatory, which he accepted, arriving in 1892. In 1893, however, the fellowship funds were re-committed to an eclipse expedition to Chile, so he had to depart.
He became an instructor of astronomy, first at the University of Michigan, followed by the University of California. From 1893 until 1898 he worked at the Detroit Observatory, where he studied variable stars and comets.
By 1897 he gained his Sc.D. from the University of Michigan with a thesis on the "Orbit of Psyche". In 1898 he spent a year on leave to travel through Germany, visiting major observatories in Berlin, Leipzig, and Munich. After his return he began teaching at the University of California, Berkeley, and was appointed director of the International Latitude Station at Ukiah, California. While there he developed an interest in geodesy, particularly seismology.
Townley was a member of the Astronomical Society of the Pacific and served as its president in 1916, and also spent time as director and on the publication committee. He also joined the Seismological Society, and served at various times as president, secretary-treasurer, and editor of the society journal.
In 1911 he became an assistant professor at Stanford University. In a short time he became full professor, and would remain in that position until his retirement in 1932, thereafter becoming professor emeritus. Toward the end of his life he became an invalid, although he remained mentally alert until he died in Stanford, California.
During his career he published roughly 100 academic papers, and edited the contributions of many others. He was widely recognized for his editorial skills.