He is joining forces with composer Tom Cunningham to create a piece which will be staged in Edinburgh next year to help raise funds for the fight against modern-day slavery and people trafficking.
The so-called “Tumbling Lassie” featured in a little-known 1687 court case, which was raised by the showman after the girl was given refuge by a couple concerned for her welfare, but was rejected by the Court of Session.
The official ruling stated: “But we have no slaves in Scotland, and mothers cannot sell their bairns.”
The operatta will be unveiled at a fundraising ball in Edinburgh staged by a group of advocates in the city to highlight slavery and people trafficking in the modern world.
Alan McLean, a QC, has already staged two previous fundraising events with colleagues in the Faculty of Advocates for two charities - the Trafficking Awareness Raising Alliance and the International Justice Mission.
McCall Smith, a former professor of medical law at Edinburgh University, is non-practising member of the faculty.
The Edinburgh-based author, who is best known for his No 1 Ladies’ Detective Agency series, said: “The story of the Tumbling Lassie is a very moving one.
“The first time I heard it, I knew that I wanted to write about it and now I have had the opportunity to write the libretto of an operetta on the theme. It is impossible not to be profoundly moved by this extraordinary tale.
“Slavery might have been rejected by Scottish judges in the late 17th century, but unfortunately the modern evils of trafficking still persist. The story of the Tumbling Lassie still has resonance today.”
The Tumbling Lassie Committee, which is staging its next event at Prestonfield House hotel in Edinburgh in April, was originally formed after Mr McLean came across details of the centuries-old case by chance.
He said: “We simply asked Alexander McCall Smith if he would be prepared to donate a couple of his books for an auction at our previous ball, but with extraordinary generosity he offered to do much, much more than that.
“We are thrilled that he and Tom Cunningham have written this operetta especially for us and that it will have its premiere at the Tumbling Lassie Ball next spring. We can’t thank them enough.
“We have set the bar high with our previous two events, but we are sure that with Alexander and Tom’s contribution we can top that success in 2018.
“We know that every penny we manage to raise helps tackle the evils of slavery and human trafficking at home and abroad and we hope that many people will be inspired to support this unique event.”