Los Angeles, California (CNN) -- A judge granted Lindsay Lohan bail Friday night, overturning a decision earlier Friday that sent the actress to jail until a probation revocation hearing four weeks away, a court spokesman said.
Lohan can leave jail after she posts a $300,000 bond, but she must be fitted with a SCRAM alcohol-detection bracelet within 24 hours, Los Angeles County Superior Court spokesman Allan Parachini said.
Judge Patricia Schnegg granted Lohan's bail after her lawyer, Shawn Chapman Holley, filed a writ of habeas corpus just before court closed Friday afternoon, Parachini said.
"I pray to God that Shawn does the right thing and advises her to go right into rehab now, and show the judge she's serious, because in 30 days when she goes back before the judge he can do whatever he wants," Michael Lohan, her father, told CNN.
Judge Eldin Fox ordered the preliminary revocation of Lohan's probation Friday morning based on a probation report saying she tested positive for controlled-substance use. The probation revocation hearing was set for October 22.
When Holley asked the judge in court to hear her arguments for bail, he answered, "Nope."
Holley returned to the Beverly Hills courthouse to meet with the prosecutor and the judge Friday afternoon, but Fox again refused to grant bail. Holley then filed her writ with Judge Schnegg just before 4 p.m., Parachini said.
The actress showed no emotion as deputies handcuffed her hands behind her back and walked her out of the Beverly Hills courtroom Friday morning.
Her father, who watched the short hearing from the rear of the courtroom, showed his own anger outside after his daughter was taken away.
"It's a horrible situation. I just hope the judge remands Lindsay to a rehab for a longer period of time and the people in Lindsay's life that are destroying her life and leading her down the wrong path are weeded out," Michael Lohan said.
He singled out Holley for giving his daughter poor advice.
Lohan cited his daughter's court-approved trip to New York during Fashion Week, saying she stayed alone in a hotel room, which opened her up to bad influences.
Lohan's supervised probation for a 2007 drunken driving conviction requires frequent drug tests. The judge warned her last month that any failure could send her back to jail.
"Regrettably, I did in fact fail my most recent drug test and if I am asked, I am prepared to appear before judge Fox next week as a result," Lohan tweeted on September 17.
She spent 23 days in a court-ordered drug rehab program last month, which followed a 13-day jail stint imposed when a Los Angeles judge ruled that Lohan violated her probation.
Fox, who took over Lohan's case when she was released, imposed a new set of rules for her to follow until November. It included weekly counseling sessions for alcohol and drug rehabilitation, random drug tests and behavioral therapy.
"Substance abuse is a disease, which unfortunately doesn't go away overnight," Lohan tweeted. "I am working hard to overcome it and am taking positive steps."
Lohan tweeted that she was "doing what I must do to prevent any mishaps in the future."
"This was certainly a setback for me, but I am taking responsibility for my actions and I'm prepared to face the consequences," she tweeted.
Lohan made fun of her substance abuse troubles in a backstage skit broadcast during the MTV Video Music Awards earlier in September.
She appeared with show host Chelsea Handler, who was wearing an alcohol-detection bracelet like the one Lohan recently wore.
"Wake up, Handler; pull it together," Lohan said as she slammed Handler against a wall. "You're a menace. Do you think anyone will work with a drunk? Take it from me, they don't."
Lohan was arrested twice in 2007 on charges of driving under the influence, and in the second incident, she was charged with cocaine possession.
The first arrest came after Lohan lost control of her Mercedes-Benz convertible and struck a curb in Beverly Hills.
Just two weeks after checking out of a Malibu drug and alcohol rehabilitation facility, she was arrested again in July 2007 after a woman called Santa Monica police, saying Lohan was trying to run her down with a car.
Lohan's acting career, which started at age 10 on a soap opera, took off on the big screen a year later, when she played identical twins in Disney's remake of "The Parent Trap."