This got me wondering if it could be made to be entirely mechanical. Like, the approaching ball triggers something to move in front of the magnet 'switching it off', then slides away again when the ball has passed, ready for the next run.
I think I just invented perpetual motion...