Gregory was the fourth son of Isabella MacLeod and James Gregory, and was born at 2 St Andrew Square in Edinburgh,. After a medical education he graduated at the University of Edinburgh in 1828, and moved into chemistry, studying at the University of Geissen. In 1831 he introduced a process for making the "muriate of morphia", which came into general use. "Gregory's salt" in terms of modern chemistry was a mixture of morphine hydrochloride and codeine hydrochloride, obtained from opium by use of calcium chloride. In the 1830s he is recorded as living in his father's townhouse with his brothers at 10 Ainslie Place on the Moray Estate in the western New Town of Edinburgh. In 1832 he was elected a Fellow of the Royal Society of Edinburgh, his proposer being Robert Christison, and served as the Society's Secretary from 1844 to 1858. After studying for some time on the continent he established himself as an extra-academical lecturer on chemistry at Edinburgh. He was appointed Professor of Chemistry at the Andersonian University, Glasgow, and then at the Dublin Medical School, and in 1839 was appointed professor of medicine and chemistry in King's College, Aberdeen. In 1844 he was elected to the chair of chemistry at Edinburgh in succession to his old teacher Thomas Charles Hope. Andrew Fyfe filled his post in Aberdeen having unsuccessfully also contested the Edinburgh chair. He was a successful expository lecturer, but in his later years suffered much from a disabling disease. Gregory was interested in animal magnetism and mesmerism. He died at his home on Princes Street on 24 April 1858, leaving a widow and one son. He is buried in Canongate Kirkyard on the Royal Mile. He shares the grave with his siblings, adjacent to his parents. It lies in the south-west corner of the graveyard, to the right hand side of Adam Smith's grave.
Works
Gregory was a pupil of Justus von Liebig at Giessen, and translated and edited several of his works. His own chemical works gave prominence to organic chemistry. A list of forty chemical papers by him was given in the Royal Society's Catalogue of Scientific Papers. Restricted to a sedentary life, he wrote a number of papers on diatoms. His books were:
Outlines of Chemistry, 1845; 2nd edition, 1847; divided subsequently into two volumes, The Handbook of Inorganic and Organic Chemistry respectively, 1853; the latter was issued in Germany, edited by Theodor Gerding, Brunswick, 1854.
Besides editing English editions of Liebig's Animal Chemistry, Chemistry in its Applications to Agriculture and Physiology, Familiar Letters on Chemistry, Instructions for Chemical Analysis of Organic Bodies, Agricultural Chemistry, Chemistry of Food, and Researches on the Motion of the Juices in the Animal Body, Gregory translated and edited Karl Reichenbach's Researches on Magnetism, Electricity, Heat, &c., in their relation to Vital Force, 1850. He also, with Liebig, edited Edward Turner's Elements of Chemistry.