Matthew Paul Foreman, 45, was before York Magistrates’ Court for three shoplifting offences as he continued to add to his long criminal record for theft.
He was also charged with failure to obey a community order imposed in March for other offences by not attending rehabilitative activities aimed at helping him stop breaking the law.
Deputy district judge John Spencer said it would be easy to send him to jail.
But after hearing that the probation service was willing to arrange mental health treatment for him, he decided not to lock him up.
Instead he gave him a 12-month community order with 12 months’ mental health treatment and 10 days’ rehabilitative activities and ordered him to pay £40 compensation to each of the shops he had raided.
“I hope you grab this opportunity with both hands and we don’t meet again,” he told Foreman.
Foreman, of Union Terrace, central York, pleaded guilty to stealing items worth £280 from Sainsbury’s in Haxby and items worth £57.99 from B&M at Clifton Moor, both on September 30, stealing items worth £74.75 from McColls in Moorcroft Road, Woodthorpe, on September 4, and breaching a community order.
He has 267 previous convictions, including 134 for shop theft and other dishonesty and has served several prison sentences.

