He was one of five sons of James Macgregor and Margaret (née Grant) of Inverness-shire, Scotland. He was created a baronet on 17 March 1828 a few months before his death in his long-term home area of Saville Row in London.[5][6] He was succeeded in his baronetcy by his eldest son William.[7]
Macgregor married Bridget Glenny on 12 November 1806 at St George's, Bloomsbury, Middlesex.[8][9][10] Bridget survived her husband dying in Brighton, Sussex on 20 July 1863. The couple had two sons (who would both succeed to the baronetcy) and four daughters.[11]
It was as the Surgeon at the Royal Military Asylum (first appointed in 1804) that Macgregor achieved some of his most effective contributions to medical science. The institution was home to up to a thousand children and communicable disease was commonplace and caused death and disability.[14][15] Macgregor was able through the study of diseases occurring amongst the children at the asylum to take action that effectively prevented transmission in some of the diseases, he was a great proponent of hygienic countermeasures.[16]
Macgregor wrote in 1811 that 'Egyptian Ophthalmia' (Trachoma) in the army had: 'at different periods materially interfered with its discipline and efficiency. It has crippled many of our best regiments to such a degree as for a time to render them unfit for service'. The problem was exacerbated by lack of understanding of the nature of Trachoma, its causes and what could be done to combat the ailment.[17] Macgregor had identified that contact with the patient's eye discharge was clearly the cause of transmission.