Surveillance video shows the attacker striking the victim on the head, leaving him unconscious.
The video was released by police to the public, hoping someone would be able to identify him, but a police officer ended up later spotting him at the scene of the crime.
"One of our Tenderloin officers, around 10:45 p.m., spotted the individual, the suspect, right on the corner of Larkin and Geary," said San Francisco police officer Carlos Manfredi.
Robert, the homeless man who is described by people who know him as a nice guy, is still in critical condition.
"Regardless of whether or not you're homeless, you know everybody has a right to feel safe," Manfredi said.
The suspect faces charges of attempted murder and aggravated assault.