I recently read on wikipedia that Benjamin Franklin once owned slaves. I never considered that slaves would work in shops and in cities before. Were there a significant population of slaves working in cities at that time? What kind of jobs did they do? Did they ever work in factories at one time?
There were a significant number of slaves living in cities. In New England, a the percentage of slaves in urban areas was higher compared to rural areas. The range of occupations was quite broad. As you suggest, they worked in shops, and also as unskilled labor (e.g. docks) and as domestic servants. Men would often learn a trade, providing goods for the shops, thought this trend dropped off as the antebellum era progressed due to sometimes violent opposition by white competitors. The latter two had their counterparts in plantation jobs, with every house needing "house slaves" and many larger plantations holding their own skilled work force.
I know of one instance of slaves as factory labor, at Tredegar Iron Works in Richmond, where slave artisans worked particularly in the rolling mills. The owner planned to use slaves as the primary labor force causing conflicts with skilled Northern and foreign labor led. An 1847 strike, whereupon the owner fired most of the white labor was followed by an increase in salve labor and a drop in productivity due largely to a lack of training. The factory had trouble hiring white workers in the following years, and the owner relaxed his insistence on using slaves as skilled labor, though slaves still worked at the factories.
*Edit: Found the statistic. In 1850, Virginia manufacturers used slaves as 58% of their labor; by 1860 this had fallen below half.
Gregg Kimball's American City, Southern Place: A Cultural History of Antebellum Richmond contains a chapter concerning Tredegar.
Follow up to this because it's a very interesting question: what about during the full-blown plantation days in the 1840s-1860s when most slaves were being used on plantations? Were slaves used in southern cities often? Was being a "city-slave" the better situation to be in?
I'm guessing you mean in the US?
In Cuba, a fair amount of slaves worked or lived in the cities. It wasn't really until the 19th century that plantations became the predominant social organization of the slave system (which happened alongside a general colonial policy that began to emphasize exporting sugar and other crops). That actually led to a pretty radical transformation of legal rights of slaves, as the rise of plantations (primarily in Western Cuba*) gave planters more authority (and effective domestic sovereignty) over their slaves. Prior to that, the colonial government was able to regulate slavery within the restrictions of colonial law.
As to what they did in the cities, it's sort of difficult to answer this because there's such a wide range of things they could do. Some worked as cobblers/other types of artisans, many worked as domestic laborers, etc. Many in coastal cities were also sailors (interestingly enough, this produced some tensions between 19th century Haiti and imperial powers in the Caribbean after Haiti instituted its free soil law). I'd venture to say that it's unlikely many slaves ever worked in factories in the US South or the Caribbean because industrialization was uneven and often not as advanced as it was in the North, although I'm sure there are cases where this could foreseeably be the case. There's no real reason they wouldn't be used in factories except for the relative scarcity of factories in areas that still predominantly depended on slave labor.
A good book on this is Alejandro de la Fuente's Havana and the Atlantic in the Sixteenth Century, which deals more broadly with the evolution of Havana as an urban space but which focuses a lot on the place and role of slaves in the incipient Cuban society.