A 58-year-old man accused of trying to assassinate former President Donald J. Trump acknowledged in a prewritten note that he had planned the attack — and even predicted his failure, according to a federal court filing on Monday.

The man, Ryan W. Routh, staked out the grounds of Mr. Trump’s golf course in West Palm Beach, Fla., for a month before the episode, the filing said. He positioned himself outside the fence at the sixth hole of the course on Sept. 15, before a Secret Service agent scouting one hole ahead of the former president’s group spotted him and the barrel of his gun.

At the time he was seen, Mr. Routh had aligned himself directly to the sixth hole, with the intention of shooting Mr. Trump from a relatively short distance with a semiautomatic rifle, prosecutors said. The rifle, equipped with a scope and left at the scene, had a bullet in the chamber and a total of 11 rounds. Investigators also found Mr. Routh’s fingerprint on the weapon.“This was an assassination attempt on Donald Trump but I failed you. I tried my best and gave it all the gumption I could muster,” Mr. Routh wrote in a note placed inside a box, left at a friend’s house, found by investigators after he was arrested. “It is up to you to finish the job; and I will offer $150,000 to whomever can complete the job.”