A sex attacker who targeted lone women walking to their work was caught after he left his own details on the phone of one of his victims.
Shane Stewart preyed on two strangers on the same day as they made their way through city streets towards their employment.
The High Court in Edinburgh heard that Stewart, 25, left one of his victims terrified and fearing he was going to rape her.
The woman started shouting for help and a passing van driver responded and stopped his vehicle to come to her aid.
Another woman was left crying and pleading for Stewart to stop during an attack he launched on her.
But the court heard that during the incident with the woman, who ended up crying, Stewart had asked if she used social media and to hand over her phone.
Advocate depute Mark Mohammed said: “He asked if she was on Facebook and asked for her phone so that he could add himself as her friend.
“She handed him the phone and he searched for his name and sent himself a friend request from her Facebook account before handing the phone back to her.”
Police were contacted after the attacks on the women in Edinburgh on the morning of October 25 last year.
Mr Mohammed said: “The complainer was able to provide police officers with the name and image of the accused as he had added her as a friend on Facebook.”
Officers turned up at Stewart’s home and found him at the address changing his clothing.
Stewart admitted committing the two sex assaults when he appeared at court on Thursday via a live link to prison.
He pleaded guilty to sexually assaulting the first victim, aged 20, at East Market Street, Edinburgh, by touching her on the body, seizing her waist and pushing her into a window. He also pushed her onto a bench and squeezed her neck after making violent threats.
He further pleaded guilty to assaulting the second woman, aged 26, at West College Street, with intent to rape her.
During the attack he approached her from behind and placed his arm around her neck, made violent threats and sexual remarks to her, and molested her.
The court heard that Stewart has previous convictions for assault and threatening behaviour and has been made the subject of non-harassment orders aimed at protecting women.
The advocate depute said both the latest offences involved Stewart approaching young women in the city centre who were unknown to him before subjecting them to assaults.
The younger woman was heading for her work when she felt a tap on the shoulder. Stewart asked her if she wanted to go for a drink and asked for a cuddle, but she refused him.
Mr Mohammed said that during the incident the woman was scared and was wanting to get away.
At one stage Stewart pushed her face into the window of a Premier Inn hotel and she banged on it to try and seek help.
Stewart followed the second woman and grabbed her round the neck and pushed her against a wall. He groped his victim and rubbed himself up against her during the assault.
Defence solicitor, advocate James Keegan QC, said Stewart had been examined by a doctor from the high security State Hospital at Carstairs, South Lanarkshire.
Mr Keegan said: “He does understand the proceedings and is able to participate effectively in the proceedings.”
Judge Fiona Tait deferred sentence on Stewart for the preparation of a background report and risk assessment. He was placed on the sex offenders’ register.