First offender Steven Douglas, who is 22, pleaded guilty to an assault and robbery offence at the Gala Park Post Office in Galashiels, on the afternoon of Wednesday, May 1.
He presented a kitchen knife towards the postmaster while wearing a black balaclava and robbed him of £150.
Depute fiscal Louise Alexander said that following a media release of CCTV footage, Douglas was recognised by his mother who telephoned the police.
Defence lawyer Greg McDonnel said it was an unusual case as Douglas had never been in trouble before and it was an extremely serious first offence.
At the time of the offence his client was using non-prescribed drugs every day and drinking alcohol to excess, and had incurred a significant debt.
Mr McDonnel said:”There was an element of pre-planning as he took the kitchen knife and balaclava from his own property.
“But he still cannot understand why he acted in the manner that he did.
“In his own words it was an hour of madness.
“The postmaster was not injured, but he was quite shaken. My client has written a letter of apology to him.
“It would be an easy option for the court to send him to jail, but this would not benefit anyone – not the complainer, not the community and clearly not the accused as he would lose his employment.
“He has turned his life around since the offence in May and the likelihood of re-offending is low risk.”
Sheriff Donald Ferguson described it as a “disgraceful incident and an appalling thing to do.”
He said it would have been a frightening experience for the postmaster and it could have ended in tragedy if the postmaster had tried to tackle Douglas.
The sheriff accepted the offence did not make any sense and while it merited a custodial sentence he had been persuaded by Mr McDonnel’s argument to give Douglas a chance.
Douglas, of Galashiels, was ordered to carry out 260 hours unpaid work along with supervision over the next 12 months as part of a Community Pay Back Order and to pay the postmaster £650 in compensation.
After the sentencing, Detective Constable Andrew Loughlin, of Galashiels CID, said: “We welcome the sentencing of Steven Thomas Douglas, who subjected the staff working within the shop to an extremely terrifying ordeal, threatening them with a knife before stealing cash from the till.
“Through thorough investigation by detectives, Douglas was arrested and charged a short time after the incident and will now face the consequences of his actions.
“I would also like to thank the public for their help with this enquiry.
“Threatening behaviour and robbery will not be tolerated in our area and we will always work tirelessly to ensure that such offenders are brought before the courts.”