Prosecutors this afternoon called the man accused of shaking down David Letterman for $2 million by threatening to expose his affairs with “Late Show” staffers “desperate” and “capable of doing anything.”

Robert “Joe” Halderman, who wore a gray suit and was brought into Manhattan Supreme Court with his hands cuffed behind his back, pleaded not guilty to attempted grand larceny charges. He made his plea in a firm, loud voice.

Bail was set at $200,000, which he posted and was released.

In arguing that bail should be set at $500,000, Assistant District Attorney Judy Salwen noted that Robert “Joe” Halderman’s is in debt and desperate. Earlier today celebrity Web site TMZ.com reported that he was forced to pay substantial child support payments.

“He is in debt to others, he has relatives across the country and we believe he is a flight risk,” Salwen said.

“The evidence is compelling,” she said. “It shows the defendant is desperate, and he is capable of doing anything.”

Halderman, of Norwalk, Conn., may have gotten his ammunition for the scheme when a woman Halderman once dated told the TV producer that she once had had a fling with Letterman, law-enforcement sources said.

She made the revelation after she and Halderman broke up several months ago, the sources said. The woman and Letterman had had a relationship prior to the birth of his son, Harry, born in November 2003.

The Manhattan DA’s office contacted Norwalk, Conn., police to get search warrant for Halderman’s house, sources tell the Post. Specifically, they were looking at electronic equipment such as a computer.

The new details were disclosed by DA Robert Morgenthau, who said the scheme began Sept. 9 when Letterman received a package at his Manhattan home. In the package, there was what was refered to as a screenplay treatment, copies of part of a diary and personal correspondence belonging to Birkitt, according to a search warrant obtained by Fox 5.

The “screenplay treatment” referred to Letterman’s “great personal success and his beautiful and loving son,” Morgenthau said. It also said his “world is about to collapse about him.”

Halderman threatened to publish a book with incriminating photos, letters and e-mails.

The package delivery was followed by a meeting at the Essex House hotel on Sept. 15 between Halderman and Letterman’s attorney, whose name wasn’t disclosed. At that meeting, Halderman demanded $2 million, Morgenthau said.

After that meeting, Letterman and his attorney contacted the DA’s office.

Letterman’s attorney had two other meetings with Halderman, one on Sept. 23 and another on Sept. 30. He recorded both meetings, Morgenthau said.

A check for $2 million, which was designed to bounced, was delivered during the Sept. 30 meeting. Halderman deposited it in his bank account in Connecticut, Morgenthau said.

Also today a possible motive for the scheme emerged. Halderman had big monthly child and spousal support payments looming over his head, court documents show.

He most recently was on the hook for nearly $6,000 in such payments every month, according to papers filed in Stamford [Conn.] Superior Court obtained by TMZ.com.

Halderman, 51, has two kids with his ex-wife, Patty Montet, who obtained a divorce from the Norwalk, Conn., resident in 2004 after claiming the marriage had “broken down irretrievably.”

That year, a judge ordered that Halderman pay Montet $6,800 per month for the support of her and the two children. That order stayed in effect for three years.

The order was modified in May 2007, reducing Halderman’s monthly payments to $5,966.66, court papers show.

Halderman’s kids with Montet are now 18 and 11 years old.

Letterman gave his own version of events during yesterday’s show.

He appeared at ease as the show began, joking in his monologue about everything from Dick Cheney to skunks riding the subway — but things changed when he sat behind his desk.

A nervously jokey Letterman told the audience, “I have a little story to tell you,” before launching into the bizarre tale.

While the audience — unaware what was coming — laughed, Letterman explained that a strange package appeared in his car weeks earlier.

“There’s a letter there. It said, ‘I know that you do some terrible things,’ ” Letterman said.

Alternately serious and silly, Letterman told the audience, “I just want to reiterate how terrible this moment is.”

He then detailed how the blackmailer told him he’d written a screenplay and book brimming with embarrassing revelations about Letterman’s life.

“This guy knows creepy stuff about me,” Letterman said.

He said he took the package to the Manhattan DA’s Office, where investigators told him to arrange a meeting to see if the blackmailer was serious.

At one point, Letterman joked that he wanted to hand over a “giant check,” like they give at golf tournaments.

But Letterman wasn’t all laughs.

“This morning, I did something I’ve never done in my life,” he said somberly.

“I had to go downtown and testify before a grand jury.”

As part of his testimony, he explained he was asked whether or not he had had steamy flings with staffers.

“My response is that, yes, I have,” he told the audience. “Would it be embarrassing if it were made public? Perhaps it would — especially for the women.

“I feel like I need to protect these people — I need to certainly protect my family.”

Letterman said he met with the suspect three times before forking over a phony $2 million check.

“I was disturbed by this. I was worried for myself, I was worried for my family. I felt menaced by this and I had to tell them [the grand jury] all of the creepy things I had done,” he said.

When he finished, the audience burst into applause.

Letterman, 62, married his longtime girlfriend, Regina Lasko, once a “Late Show” staffer, in March — after more than 20 years of dating.

Halderman allegedly concocted the extortion plot in an effort to raise money to support his kids, the sources said.

Mark Charles Montet, whose daughter was married to Halderman, said the producer seemed initially “like a nice guy.”

“But he was fooling around with a lot of women,” said Montet, a Louisiana native.