MacGregor was appointed lieutenant-governor in 1895, and retired from this position in 1898. From 1899 to 1904 he was governor of Lagos Colony, Nigeria, where he instituted a campaign against the prevalent malaria, draining the swamps and destroying as far as possible the mosquitoes which were responsible for the spread of the disease. Much other important work in developing the country was done by making roads and building a railway. His efforts to improve the health of his community led to his being given the Mary Kingsley Medal in 1910 by the Liverpool School of Tropical Medicine. He had been transferred in 1904 to Newfoundland of which he was governor for five years. Here again his medical knowledge was most useful in the combating of tuberculosis which was then very prevalent in Newfoundland. He also did valuable work in dealing with the fisheries question, persuading the contending parties to refer the dispute to the Hague international tribunal which brought about an amicable settlement. On 2 December 1909 MacGregor was appointed Governor of Queensland.