IN April 1965, Johnny Cash was in a recording studio laying down the final track on a record which can rightly claim to be country music's first concept album. It was called Johnny Cash Sings The Ballads Of The True West and, while the title was a little misleading - it contained songs by contemporary artists such as Carl Perkins, Tex Ritter and Ramblin' Jack Elliott as well as several Cash compositions - it did include others whose authorship is lost in time.

Among them was a song called Streets Of Laredo, a spare and ghostly ballad in which an unnamed narrator meets a young cowboy "wrapped in white linen" who is dying from a gunshot wound. The cowboy asks the stranger to make preparations for his funeral: Get six jolly cowboys to carry my coffin, Six dance hall girls to bear up my pall, Throw bunches of roses all over my coffin, Roses to deaden the clods as they fall.

To the drovers and farmhands of 18th and 19th century Scotland, the wild west probably meant nothing more than Bridge of Orchy on a Saturday night, and if they had heard of Laredo it was because they had seen it on a map of Spain.

But one thing is certain: they would have recognised both the tune and the lyric. In one version it was known as The Bard Of Armagh and in another as The Unfortunate Rake. The latter tells of a young man dying not from gunshot wounds but from syphilis.

The lyrical similarities are striking: Get six young soldiers to carry my coffin, Six young girls to sing me a song, And each of them carry a bunch of green laurel So they don't smell me as they bear me along.

So how did this song jump the centuries - and an ocean - and wind up on a Johnny Cash record in 1965, albeit in a slightly different form? The answer, of course, is emigrants, those Scots and Scots-Irish who left their homelands in waves after Culloden, the Highland Clearances and the Irish potato famine and who headed for the New World. They packed their clothes, bibles and fiddles into whatever containers they could find but they carried their songs - and in particular, those tunes - in their heads.

Cattle, horses and music have always been Celtic passions so it's no surprise that the Scots and Scots-Irish were among the most significant influences on cowboy lore and culture. The droving tradition in Scotland had been strong for centuries and both the perils and practices of the New World would have been familiar to those who had come from the Old.

In the early 19th century, Skye drovers on their way to the Falkirk Tryst market would take up to 6000 cattle across the water from Kyle Rhea to Glenelg on the mainland. All they did when they reached America was swap the Highlands for the Texas badlands. In a sense, the cowboy life was tailor-made for them - even if the clothes owed more to the Spanish vaqueros.

"The Scots' involvement in the American west was considerable," says Rob Gibson, author of Plaids And Bandanas: From Highland Drover To Wild West Cowboy and now an SNP MSP. "And because of Scotland's particularly strong musical traditions their songs were diffused through the eastern regions throughout the 18th century and were added to by people going to America to go out west in the 19th century. That was the second blast of Scottish culture and music and it was injected into the western way of life."

The US census carried out in 2000 showed that 4,890,000 Americans claim Scottish heritage and a further 4,319,000 claim Scots-Irish heritage. The cattle state of Texas has some of the highest numbers of both and, in terms of percentage of overall state population, they are also most numerous in places such as Montana, Wyoming and Oregon - the rugged frontier states of the old wild west. It can be no accident.

Perhaps the best-known Scottish cowboy was Jesse Chisholm, who gave his name to the famous Chisholm Trail which ran from Texas to the Dodge City shipping point, from where the steers were sent to market "back east". Another Scot of some renown was Duncan McDonald who, along with his Scots-Irish friend Billy Irvine, led a group of 11 cowboys and a herd of longhorns 1000 miles from Montana to Wyoming in the summer of 1876, exactly a century after Jesse Chisholm's grandfather had arrived in America. This too was a fateful year: McDonald and Irvine were forced into a wide detour to avoid the fallout from general Custer's defeat just weeks earlier at the battle of the Little Big Horn. McDonald Peak and McDonald Lake in Montana are both named after Duncan's father, Angus, and Duncan himself was a Gaelic speaker who would later assist the Native American Nez Perce tribe when they fought the US army in 1877.

Then there was Scotty Phillip. Born in Morayshire in 1858, he was working as a labourer in Kansas by the time he was 16. Through his marriage to a native American Indian woman he became Crazy Horse's brother-in-law and, at the time of his death in 1911, he was widely credited with having saved the buffalo from extinction thanks to the success of his buffalo ranch in South Dakota. These are just the stories of three; there were many others.

But a cowboy tradition which had started with waves of Scots heading west in search of work took on a different characteristic when Scottish capital became involved after the civil war ended. In 1877, The Scotsman sent one James McDonald to investigate the burgeoning cattle industry of the American west. He wrote a book about his experience a year later which caught the eye of the Earl of Airlie, chairman of the Scottish-American Mortgage Company. The good Earl went out to America to have a look for himself and, in the early 1880s, a number of Scottish companies were set up with the sole intention of investing in American cattle farming.

The Prairie Cattle Company which owned land in Colorado, New Mexico and Texas was founded in and run out of Edinburgh, but it was in Dundee that the real power lay: both the Texas Land And Cattle Company and the Matador Land And Cattle Company were headquartered there, the latter owning the famous Matador Ranch in Texas.

So, as well as Scottish cowboys on the prairies, there were Scottish cattlemen in the ranch houses sent out to America by the Edinburgh and Dundee companies to look after their interests, and noted for their expertise. One such was John Clay of the Swan Ranch, who fought in the notorious Johnson County war of 1892. Clay and his cohorts employed a 50-strong band of Texan gunfighters to remove homesteaders from company land and crack down on rustlers. The classic western films Shane and Heaven's Gate are both based in part on this conflict, which flared to the point that both the US army and the US President became involved.

But whether they were cattlemen or cowboys, good or bad, all these Scots emigrants took songs and music with them. Chisholm is actually commemorated in a traditional cowboy song, The Chisholm Trail, which describes life on the long drive north. "Come along boys and listen to my tale, I'll tell you of my troubles on the old Chisholm Trail " Ramblin' Jack Elliott is just one of many 20th century musicians who has recorded a version of it and Howard Hawks's seminal 1948 western Red River is a fictionalised account of the first journey along it.

Another campfire favourite was Annie Laurie, a traditional Scots ballad. For Rob Gibson, this song in particular shows the direct link between modern cowboy culture and the Scots immigrants of old.

"Because it was a slow song and because there were lots of Scots in America working as cowboys, the idea of singing slow quiet songs to bed down the cattle on the drive was very popular. You don't want to do anything to spook them so you sing soothingly. And Annie Laurie is still very popular today at cowboy poetry festivals I've got recordings of western singers singing that ballad as it is today, so it translated directly."

And the songs weren't all in English either. Many of these immigrant cowboys were Gaels who sang and composed in their native tongue. One such was Murdo MacLean who left Wester Ross for America and ended up as a cattle hand in Montana where he wrote Mo Shoraidh Leis a'Coigich - Farewell To Coigich. Sadly, Johnny Cash never recorded that one.

Tracking the roots of traditional cowboy songs isn't easy but Gibson has observed that Streets Of Laredo, as well as having The Bard Of Armagh and The Unfortunate Rake in its family tree, also bears a striking similarity to The Road And Miles To Dundee. Meanwhile another traditional cowboy favourite, The Railroad Corral, is lifted from the Scots song Fareweel To Carwathie which originated in Buchan.

"It's an ancient tune which has been used for a whaling ballad in the 19th century and then turned into a cowboy's trail ballad in the American west," says Gibson.

One man who did more than anything else to collect these songs was pioneering folklorist Alan Lomax, father of the equally celebrated musicologist Alan Lomax. In 1910, he published a book called Cowboy Songs And Frontier Ballads. It was the first serious collection of American folk songs which until then had never been written down, simply transferring from singer to singer in the time-honoured tradition. Streets Of Laredo was one of the songs that he included.

Among the book's many avid readers was president Theodore Roosevelt who wrote to Lomax to express his admiration, adding: "There is something very curious in the reproduction on this new continent of essentially the conditions of ballad-growth which obtained in mediaeval England; including, by the way, sympathy for the outlaw, Jesse James taking the place of Robin Hood."

Mediaeval Scotland or Ireland might have been nearer the mark, but it showed that even the president had noticed the connection.

Of course, by the time Lomax's book was published the frontier lands had been travelled and tamed, the Native Americans corralled into reservations and the buffalo all but exterminated. It was only thanks to another Scot - Dunbar-born John Muir - that any of the landscape had been preserved at all.

But, if the true west was dead, the mythological one was just beginning. Edwin Porter's 1903 film, The Great Train Robbery, made Bronco Billy Anderson the first screen cowboy and since then many others have followed, from Gary Cooper and John Wayne to Clint Eastwood and beyond.

Some of them have even sung. We may laugh now to think of Roy Rogers crooning When I Camped Under The Stars with equine sidekick Trigger neighing in the background, but listen to Gene Autry's version of Red River Valley and we are, once again, on an express train back in time: a song of parting and loss, its roots lie in a folk song whose provenance is unknown but which first surfaced in Canada in the mid-19th century. It doesn't take a genius to figure out its real place of origin.

On his 2002 album, American IV: The Man Comes Around, Johnny Cash reprised old favourite The Streets Of Laredo for a new audience, one which had been switched on to American folk music in the 1990s by younger artists such as The Cowboy Junkies and Wilco. This time, however, his voice is older and lower, the musical setting even leaner than before. Cash is both narrator and dying cowboy. This is far the superior version and in it the listener hears an intimation of what Alan Lomax was driving at in a 1994 interview with Studs Terkel.

"I've begun to understand why sorrow produces such songs," said Lomax, then aged 79. "The people confronted with an odd and painful situation have to dig deeper into their cultural resources and get the most profoundly strong and ancient things to help them."

Johnny Cash knew it. So too did the men he paid tribute to on that 1965 album - cowboys with Scotland on their mind and Scotland on their tongues.

The Cowboy Junkies play the ABC, Glasgow, on January 31 as part of Celtic Connections