In February 1873 MacGregor became assistant medical officer at the Seychelles, and in 1874 he was appointed resident at the hospital and superintendent of the lunatic asylum at Mauritius. This brought him under the notice of Sir Arthur Gordon who was then governor of the island, and on Gordon being transferred to Fiji in 1875, he obtained MacGregor's services as chief medical officer of Fiji. There he had to grapple with a terrible epidemic of measles, which resulted in the death of 50,000 natives. In 1877 he was made receiver-general and subsequently a variety of other offices was added, including the colonial secretaryship. On more than one occasion he acted as governor, and was also acting high commissioner and consul-general for the western Pacific. In 1884 the ship Syria, with coolies for Fiji, ran ashore about 15 miles from Suva. MacGregor organised a relief expedition and personally saved several lives; his report made no mention of his own deeds, but they could not remain hidden, and he was given the Albert Medal, and the Clarke gold medal of the Royal Humane Society of Australasia for saving life at sea. In January 1886 he represented Fiji at the meeting of the federal council of Australasia held at Hobart.
Administrator and governor
MacGregor's experience with native races led to his being appointed administrator of British New Guinea in 1888. Here he had to deal with a warlike people separated in many tribes, and his great problem was to get them to live together in reasonable amity. It was necessary at times to make punitive expeditions, but bloodshed was avoided as much as possible, and by tact and perseverance MacGregor eventually brought about a state of law and order. He did a large amount of exploration not only along the coast but into the interior. Andrew Gibb Maitland was seconded as geologist in 1891. In 1892 the position was sufficiently settled to enable him to publish a Handbook of Information for intending Settlers in British New Guinea. He was awarded the 1896 Founder's Medal of the Royal Geographical Society for his services to geography. 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. MacGregor assisted in the inauguration of the University of Queensland, he agreed to the handing over of his residence Old Government House to be its first home, and one of his first acts as governor was to attend the dedication ceremony on 10 December 1909. He also became the first chancellor and took great pride in the early development of the university. MacGregor was also president of the Royal Geographical Society of Queensland. He chaired the inaugural meeting of the Historical Society of Queensland in August 1913 and became its patron.