A hooded man threatened a shopkeeper with a knife as he tried to rob his Kirkcaldy store.
Conor Hood, 26, demanded money from Tarlok Singh at the Best-One shop in Forth Avenue.
He ran off empty-handed and was later caught by police.
Hood was jailed for 34 months when he appeared at Kirkcaldy Sheriff Court on Tuesday.
The court heard he had entered the newsagent on December 14 with his hood pulled tight to hide his face. A regular customer was in the shop at the time of the offence.
The court heard Hood pointed his knife at Mr Singh and jumped on a counter but Mr Singh pushed him. Mr Singh’s wife heard her husband shout “go away, go away”.
A detective in an unmarked police car later spotted Hood and another man and Hood ran away. He was later caught and confessed to what he had done.
Hood, who appeared from Perth prison, admitted assaulting Mr Singh, brandishing a knife at him and attempting to rob him.
He also pled guilty to offences on November 20, assaulting his ex-partner by seizing her by the clothing and dragging her down stairs and her home in Kirkcaldy and acting in a threatening and abusive manner at her flat, shouting, climbing onto scaffolding in an attempt to gain access and banging on a door and windows.
Hood’s solicitor Joanne Ritchie said her client had been abusing Valium at the time of the attempted robbery, following the breakup of his relationship, and had wanted money.
She said: “He did not have any intention of harming the complainer.
“He does appear genuinely remorseful for his actions now his is sober and able to reflect on his actions.”
Sheriff Jamie Gilchrist QC also granted a non-harassment order for 12 months in relation to Hood’s ex-partner.