Jamal Jibril, 54, turned up at the politician’s head office in Edinburgh and smashed the office front windows by throwing rocks.
Jibril, whose address was given in court as Access Point, Leith Street, claimed he attacked the property at the city’s Haymarket area because he “doesn’t like the Tories”.
Two office staff who were within the office at the time of the attack were said to be shaken by the incident.
Ruth Davidson, 40, was not within the office at the time of last month’s vandalism attack.
The shocked office workers called in the police moments after the rock was hurled through the window and when officers arrived at the scene shortly after they found Jibril standing outside waiting for them.
And when he was searched officers found Jibril, originally from Paisley, was also carrying cans of spray paint and said he intended to deface the political office.
Jibril pleaded guilty to culpably and recklessly throwing rocks at the Conservative Party office window to the danger of injury to two women at Roseburn Terrace, Edinburgh, on November 22 this year when he appeared at the capital’s sheriff court from custody last month.
He returned to the capital court for sentencing today, and Sheriff Robert Fife told him he was fortunate not to be spending the festive period in jail.
Sheriff Fife said: “I wish to put on record that this was a very serious offence and was a very serious public order offence which was frightening for the individuals within the Conservative Party office.
“But for the fact you have a very minor previous convictions of some vintage I would certainly be sending you to jail.
“But I am not going to do that today as there is an alternative and I am giving you a very clear warning that if you appear on summary again you will be going to prison.”
Sheriff Fife sentenced Jibril to carry out 250 hours of unpaid work within the next nine months and ordered a review in February next year.
The sheriff added: “If I do not get glowing [social work] reports I will revoke the order and impose a period of imprisonment.”
Solicitor Katie Bell, defending, said her client was “remorseful” over the vandalism attack and that his “actions were not to harm anyone”.
Mrs Bell added Jibril is currently living in temporary accommodation and that he “now knows this kind of behaviour can end up with him in serious trouble”.
The brief added: “I have explained unpaid work to him and that is something he will do.”
Ruth Davidson has been leader of the Scottish Conservatives since 2011 and she gave birth to her first child, a boy named Finn, on October 26 this year.
Davidson and partner Jen Wilson, 33, announced the pregnancy earlier this year after the Tory leader had received IVF treatment.
Join our Facebook group Our Edinburgh to share images and news from and around the Capital