Mark Hay, 33, had been on a "bender" when he attacked barman Ross McLennan, in Carter's Bar in Morrison Street, Edinburgh, on 8 August last year.
Hay, of Orwell Terrace, Edinburgh, had admitted the assault at the city's Sheriff Court previously and sentence was deferred until yesterday for reports.
Fiscal Depute Faith Currie told Sheriff Derrick McIntyre that at around 12:45am, Hay had gone into the bar, but left when he was told to stop being aggressive.
He returned half an hour later carrying a bottle and hurled it at Mr McLennan. The barman ducked and the bottle smashed a 120 spirits optic on the gantry.
Solicitor Advocate David Allan commented: "This was completely unacceptable drunken behaviour. He had been on a bender and took the view the barman had been staring at him."
He added: "It was more like a scene from a cowboy western."
Sheriff McIntyre gave Hay 150 hours' community service and told him to pay compensation of 120. He added: "If the bottle had hit the barman you would, very likely, have been going to prison."