 He was made principal clerk of the General Assembly in 1827, but unsuccessfully contested the moderatorship with Thomas Chalmers in 1832.In 1834 he became minister of the old church of St. Giles's, Edinburgh, in 1837 Principal of the United College, St Andrews, and in 1840 Dean of the Chapel Royal, Stirling.In 1840, also, he was elected Principal of the University of Edinburgh.