Applecross and Dalkeith residents may have previously noticed bright red objects hanging in their local street trees.
These were traps for the native orchard pest - Light Brown Apple Moth, part of a Department of Agriculture and Food trial to develop better ways to eradicate outbreaks of insect pests in urban areas.
Department senior technical officer Ian Lacey said in an innovative approach to reduce the moth population, fruit flies were used to confuse the male moths and prevent them from mating.
Mr Lacey said female moths attracted male moths by releasing a pheromone scent and creating a perfumed trail for the males to follow.
"In the trial, thousands of sterile male fruit flies were released carrying minute amounts of moth pheromone on their bodies," he said.
"The male moths were attracted to the pheromone-laced fruit flies and were unable to find the female moths."
Mr Lacey said the department would like to thank the local residents for their cooperation and interest in the trial.