An old trick for automating a Lionel or Marx train layout is to power accessories off an insulated rail section. Run one wire to the center rail, then run the other wire to a rail that’s been insulated from the other rail and the two adjoining track sections. A passing train completes the circuit, causing the accessory to activate.
You can buy insulated O27 and O31 straight tubular sections. If you want a curved insulated section, or if you just want to save some money, you’re better off making your own.
The usual way is to take a piece of track, pry up the pair of tabs holding the rail on one side of each tie, and then insert some kind of nonconducting material–a piece of electrical tape or a piece of cardstock are popular options–and then mash the tabs back down onto the tie. Then you insert a Lionel o27 insulating pin or o31 insulating pin into each end of the rail you just insulated. I’ve also made my own O27 insulating pins out of bamboo skewers from the grocery store. (I don’t know about anyone else’s schedule, but most hobby shops aren’t open at 9 PM, which is usually when I get time to work on my layout.)
But there’s another way that you might like better. Pry up all of the tabs on the metal ties and set them aside. Cut similar-sized ties from a piece of wood. Popsicle sticks are close enough for O27 track ties, or you might want to buy a strip or two of basswood of appropriate size from a hobby shop. Nothing stops you from cutting extra ties, if you like your track to have more than the usual three. Stain or paint the ties the color you want, and then glue the ties right to the rails. Cyanoacrylate (superglue) or epoxy is best. Insert insulating pins (store bought or homemade) and you have an insulated track section.
What to do with the extra metal ties you just removed? If they’re in reasonably good shape, you can put them on other pieces of track to improve their appearance a bit. If you don’t like that idea, save them and once you get a decent quantity, sell them on Ebay so someone else can put them on other pieces of track to improve their appearance a bit.