Matthew and Daniel Libman get their happy beginning with the latest episode of the ABC sitcom “Happy Endings.”

The series, which debuted April 13, revolves around six Chicago friends played by Elisha Cuthbert, Damon Wayans Jr., Eliza Coupe, Zachary Knighton, Adam Pally and Casey Wilson.

The Libman brothers, who grew up in Glencoe, wrote “Like Father, Like Gun,” which airs at 9 p.m. Wednesday. In it, Wayans Jr.’s character, Brad, has to deal with his father (played by Wayans real dad, Damon Wayans), who cuts loose after medical tests show he’s healthy.

It’s the first script from Matthew and Daniel to be produced for a network TV show. “Yep, that’s a Libman joint,” Daniel joked during a recent interview in West Hollywood.

So, too, is Cookers Red Hots in Deerfield—a hot dog joint the brothers told RedEye they dearly miss—one of many fun asides that help explain how they went from growing up “trying to make each other laugh,” as Daniel said, to cracking up the conference room of a top PR agency in L.A.

Matthew, the older Libman, attended New Trier High School before studying music at the New England Conservatory in Boston. He moved to L.A. in 2003 to work in the music business, but when that industry hit the skids he hooked up with some friends who were feature film writers.

One of those friends was David Capse, who would go on to create “Happy Endings.” Capse, who has been best friend with Matthew since third grade at South School in Glencoe, encouraged Matthew to pursue TV and film writing.

“I never wanted to do it because they made it sound horrible,” Matthew said. “You sit in your room by yourself and you’re banging your head against the keyboard and you’re hating yourself.”

Before Daniel joined his brother in L.A. about 18 months ago, the Highland Park High School graduate was writing blogs about the Olympics and other life experiences.

“I was living with my parents in Chicago and some of [Matthew’s] friends had read my blog and said that I should give [script] writing a try,” the University of Iowa graduate said. “At that time I was like, ‘If I don’t just take a swing at something, I’m going to go crazy.’ So, I just started to write this thing. I had no idea what I was doing.”

The “thing” was actually a TV pilot that Daniel sent to Matthew for his feedback. But Matthew’s notes turned into additional pages. It was at that time that the brothers decided to collaborate.

“It became so much fun that we just determined we were going to be writing partners,” Matthew said.

Added Daniel: “We decided to just take a crack at it and if it worked, it worked. If it didn’t, it didn’t.”

A month after completing their first pilot script about a “super” dysfunctional family, the Libman brothers were signed by Creative Artists Agency, and they hired a manager. The pilot, which Matthew now says was “wildly un-producible,” never got made, but the brothers were hired to work on “Robot Chicken,” a gig that led them to jobs as staff writers for “Happy Endings.”

“It’s been kind of whirlwind, and so much fun,” Matthew said. “Anyone who knows us will tell you that Daniel and I are super close. The fact that we get to work together doing something we both love—it doesn’t get more awesome than that.”

So far, the key to their success as partners has been to play to their strengths. Daniel does the typing—because he’s faster—while Matthew lies on the floor or sits in a recliner and dispenses pearls of humor.

“The rule is if we both laugh at it and it’s funny then it goes in,” Daniel said. “That’s how it works. When it’s good we sort of know it and when it’s not good we sort of know it.”

Sometimes what they think is funny can be extreme. Matthew remembers bad ‘80s sitcoms with too-happy endings they watched as kids.

“I would think things like, ‘This moment in “Saved By the Bell” is so heartfelt, but wouldn’t it be funny if they got run over by a train?’”

Miki Turner is a RedEye special contributor.