The First Minister shared a stage with the author, reading passages from his Laidlaw trilogy and taking part in a question-and-answer session.
But an audience member interrupted to complain she had not come to hear the First Minister talk about independence, and was cheered by others.
McIlvanney was promoting the re-issue of his celebrated crime trilogy. He voiced guarded support for independence, telling the audience that on balance he would vote Yes.
Speaking afterwards, he confirmed he had not been approached to write the foreword to the Scottish Government's White Paper on independence, expected in the autumn, which will set out detailed policies.
He was linked with the role after it emerged the Government was considering hiring a literary figure to pen an inspiring introduction.
He said: "The first I heard about it was when it was written in (a) newspaper and I haven't heard anything since."
Asked if he would agree to write the introduction, if asked, he said: "I'm not going to answer that."
On the wider issue, McIlvanney told the audience: "I can understand people's hesitation or wishing to vote the other way but having thought it through as well as I can, I would rather take the chance of being a small country dealing directly with that kind of monstrous juggernaut of finance, rather than doing it indirectly through a government which I think will surrender and kowtow to them any time."
During the talk, he also hit out at Labour, describing the party as "dead in the water".
He said: "I really believed when we got the Parliament that a lot of socialist principles would surface in Scotland.
"But the truth is the Labour Party's now dead in the water. We voted Labour for generations. Now we've got the Parliament, there is no Labour Party."
Expressing dismay at British politics in general, he added: "Nobody, it seems to me, is still haunted by some kind of social idealism, which I think politics should really be about, whereby you don't just run the country, you try to make it fairer, you try to make it more just.
"That's where my present dismay in politics resides. It's essentially a dismay with British politics."
A spokesman for Mr Salmond said: "The First Minister enjoyed taking part in this year's Book Festival, and answering the questions put to him by an audience who were clearly interested in the current constitutional debate."