Aaron Sorkin's bungalow office on the Warner Brothers lot feels more like a college library than a Hollywood writer's room. It is spacious, wood-panelled, comfortable and cluttered. There's a huge wooden table surrounded by sofas, and pictures of Tennessee Williams, George Bernard Shaw and Arthur Miller hang from the walls, while at the centre of the table is that least Hollywood of accoutrements - an ashtray. Sorkin settles himself in a hard-backed chair and gets ready to spark up a small cheroot.
"Mind if I smoke?" He smiles expansively. "Feel free if you want to as well . . ."
The writer of A Few Good Men and The West Wing seems surprisingly relaxed for one of the US right's favourite hate figures. Sorkin has donated hundreds of thousands of dollars to the Democrats, has written an anti-Bush ad for MoveOn, and is about to deliver a movie based on the Texas congressman Charlie Wilson's funding of CIA activities in Afghanistan during the 1980s. Republican wags dubbed The West Wing "the Left Wing" for its perceived liberal bias, and any project to which he is attached faces a stream of abuse and bile from the word go.
"This is a country that has been very polarised, especially since 9/11," he agrees. "There's the left versus the right, and religious people versus less religious people, and popular entertainment has been in the cross-hairs for quite a while. Hollywood's patriotism is always being questioned - that we're too liberal.
"There's a man named Frank Luntz; he's a professional pollster and I know him because he did a lot of consulting on The West Wing. He went on Chris Matthews's show Hardball a couple of months after 9/11 and said: 'You know, I was just on the Warner Brothers lot and I was looking around the car park. I could not find one car with an American flag sticker and I could not find one lapel with an American flag. Isn't that just typical of liberal Hollywood?' We weren't patriotic enough for this guy because we didn't have a bumper sticker on our car."
His counter-attack is Studio 60 on the Sunset Strip - a witty drama in the classic Sorkin mould, with lots of snappy walk'n'talk dialogue, clever sub-plots and tense romance. It was the most widely anticipated launch on US television last autumn and Channel 4 has snapped it up as the centrepiece of its summer schedule. The script was good enough to tempt Matthew Perry back to television after the multimillionaire Friends star had resolved to do film work only. His character, Matt Albie, has to save the eponymous failing sketch show (loosely based on Saturday Night Live) and deal with his ex-girlfriend, a Christian who also happens to be Studio 60's main comedian. There are a few West Wing faces - Bradley Whitford, who plays Josh Lyman in The West Wing, pops up as Matt's producer/director buddy Danny Tripp - but it seems a curious leap from White House to TV sketch show.
"One of the reasons I wanted to set the show behind the scenes at a late-night sketch-comedy show was that it seemed like a good place for conflict in terms of the culture wars," Sorkin argues. "TV is important because we all watch it. It has the ability to do damage and it has the ability to lift us up. In the US, the Federal Communications Commission [FCC] and the religious right have a comprehensive influence over broadcast television. They are the law, and they have the networks on a very tight leash."
As a result, Studio 60 deals with swearing during live news broadcasts from Afghanistan - which draws on last month's decision by PBS to show the documentary Operation Homecoming: writing the wartime experience, despite potentially hefty FCC fines for the obscenities that US soldiers who appear in the film use to describe their experiences in Iraq. It shows the pressure from Midwest network affiliates and Christian campaign groups, and even takes a swift look back to 1949 with a history lesson on the Hollywood Ten and blacklisting.
"I went to school in New York with the children of people who were blacklisted and the children of people who named names," Sorkin explains. "Any time there was an assembly or a school play when parents would come to the school, there would be fist fights out in the lobby and the kids didn't know why. So I decided to make a point about this polarisation that feels an awful lot like the early 1950s, with screenwriters being asked, 'Are you patriotic enough?'"
Indeed, Studio 60 constantly makes reference to Sorkin's life. The relationship between Matt and Danny echoes his own bond with the director Thomas Schlamme, and the Matt/Harriet Hayes romance is clearly based on his love affair with the West Wing actress and singer Kristin Chenoweth. Sorkin split with Chenoweth after she appeared on the controversial evangelical Christian show The 700 Club to promote an album. Matt gives the same reason for ending things with Harriet.
"This was quite a personal project for me," Sorkin admits. "The things I had written had been so removed from my actual life - the White House, a navy law office and a court martial - so I thought, 'I'm older now: I'm a father, I'm a recovering cocaine addict, I love the world of television. Why not be writing about some of these things?' I didn't want to write a memoir and I didn't want to make it autobiographical, but why not write just a little more personally?"
It was a risky move, and although the political wind appears to be changing direction in the United States, his heart-on-sleeve approach has not wooed the viewing public. Studio 60 kicked off with high ratings and critical plaudits, but the numbers fell rapidly, and it seems unlikely - even though NBC has yet to make an official decision - to win a second series.
"NBC has been as supportive as you could hope from a network," Sorkin says cautiously. "As far as ratings go, I have to pay attention to them, because it's life or death for the show, but I don't say: 'Well, gee, we're not doing well with women 18-34 so let me try to write something that will get women 18-34.'
"I don't write as if I'm fishing with bait. I just write what I think is good and I hope that word of mouth does the rest." He smiles. "If you want to ask how I measure my success, Butch Cassidy and the Sundance Kid was the first time I saw a movie and wanted to write the screenplay. That was just fantastic. So basically, I just keep trying to write Butch and Sundance."
"Studio 60" starts on Channel 4 in June