William was educated at Fettes College, Edinburgh, and at qualified Edinburgh University, qualifying M.B., C.M. in 1882.
He gained a commission in the Medical Services, at the rank of Surgeon Captain on 3rd February 1883. In 1892 he accompanied British Missions to Morocco in 1892 - which he did again in 1896, and was the First Medical Officer of Health, Gibraltar from 1892-1897. During this time he took a diploma in public health [D.P.H.] In 1893, and was promoted to the rank of Major on 3rd February 1895. In 1897 he was selected to attend the 6th Congress of Red Cross Societies in Vienna, and from 11th January 1899 to 30th April 1902 held the appointment of Deputy Assistant Director-General, Army Medical Services at the War Office.
During this time he was awarded the Knight of Grace Order of St John of Jerusalem in 1901; received the Companion Order of St Michael and St George, and was selected to attend the 7th Congress at Petrograd in 1902. From 1902 to 1903 he was a member of Advisory Board for Medical Services. On 3rd February 1903 he was promoted to Lieutenant-Colonel. He was attached to the Japanese Army in Manchuria from 24th March 1904 to 21st December 1905, and saw action in the Russo-Japanese War - being “Granted next higher rate of pay for his rank” on 17 March 1906, for special service with the Japanese Force, operating in Manchuria. He also received the Japanese War Medal and Order of the Sacred Treasure (3 Class) in 1907, and the Meritorious Service Medal of Japanese Red Cross Society in 1908. From 29th October 1906 to 28th December 1909, he held the appointment of Deputy Assistant Director-General, attached to the Department of the Director-General of Military Operations, Headquarters of Army and War Office. During this time he was one of the British Plenipotentiaries at the Conference for the Revision of the Geneva Convention, and received the C.B. [Mil.], both in 1906. He was promoted to Colonel on 6th March 1910, and was appointed King’s Honorary Physician in 1912.
From 6th March 1914 to 14th October 1914, William held the appointment of Deputy Director-General, Army Medical Services at the rank of temporary Surgeon-General - being promoted to Surgeon-General on 14th July 1914. This appointment was in succession to Surgeon-General W Babtie, and he was operating in this role at the outbreak of war. Leaving this role - being succeeded at the War Office by Col M W Russell - he entered the war in France on 17th October 1914 and was appointed as advisor for medical services of the Indian Contingent. He then became Director of Medical Services with the First Army from the 29th December 1914 up until the 25th December 1915 when he was appointed Director of Medical Services with General Headquarters for the British Salonika Army.
In March 1916, he took Surgeon-General T J O'Donnell's place back in France after he had been recalled from Salonika at the request of the Commander-in-Chief, for special duty in connexion with the impending operations on the Somme. These duties involved constant supervision of the medical arrangements in the front areas, and as Hesdin was nearer the army areas than Montreuil, he made his headquarters with the Director-General, Army Medical Services there.
He received the Order of the Crown of Italy (Commander) in 1917. By the end of January 1918, he had reached the age limit and was due to retire, but sanction was given for his continuing to serve as Deputy Director-General until the termination of Sir A Sloggett's term of office. He was appointed editor-in-chief and given the task of organizing the writing of the Medical Official History of the Great War. He was also the author of many publications throughout his career. William became known as "Tiger Mac" on account of his energy and thoroughness. He was later appointed Colonel-Commandant of the R.A.M.C.