A former soldier planted a tracking device on his partner's car to monitor her movements, a court has been told.
Scott McNee, 44, claimed he was concerned for Sharon Carr's safety.
But he pleaded guilty to stalking Ms Carr between 7 and 10 September this year.
Appearing for sentence at Livingston Sheriff Court, McNee was ordered to carry out 100 hours of unpaid work under a community payback order.
McNee was said to have drawn on his army training to track her.
He said he was concerned for her safety because he thought she was meeting people to take drugs.
But when McNee turned up unexpectedly at a pub car park he was "shocked" to discover she was meeting a former boyfriend.
Ms Carr called the police when she discovered McNee was able to follow her and officers found a hidden global positioning system (GPS) device on her car.
Assistant procurator fiscal Deborah Demick told the court: "The complainer was upset at the accused turning up unannounced. She didn't make it into Beefeater, this happened in the car park.
"Some days prior to this there was a 'chance' bumping into each other which aroused her suspicions because he was turning up where she was, unwanted.
"It emerged that the accused was aware of her movements because of the tracking device he had put into her motor vehicle."
She added: "The accused was detained and he admitted purchasing the tracker and putting it in his ex-partner's car without her knowledge."
McNee admitted the offence - aggravated by "involving abuse of an ex-partner" - at addresses in Livingston and Bathgate in West Lothian, and at his former home in Kirkcaldy, Fife.
Iain Smith, appearing for McNee, admitted the behaviour "appeared sinister at first blush".
But, he said: "He was afraid she was taking drugs. What he didn't suspect, and what he was horrified to find out, was that she was having an affair.
"That wasn't the normal type of controlling behaviour that goes on. He says he took the device which was on his motorbike and put it into her car because he felt she may have been going and getting drugs."
Mr Smith added: "His ingenuity may have been assisted by his prolonged period as a soldier in the armed forces for 15 years.
"Thereafter he was in close personal security both in Afghanistan and Iraq. Perhaps that didn't assist his thought process. He accepts he's done the wrong thing."
Passing sentence, Sheriff Kevin Drummond said: "You claim to have done this out of concern for your then partner's safety.
"That may be what you say, but I have to say that I agree with the author of the social inquiry report who expresses the view that this is extreme and controlling behaviour.
"Nonetheless, the relationship has now concluded and I consider I can deal with this by other than a custodial sentence."