How to automate changing the background color of a line

Thanks! I have opened a follow-up at Changing the background color of a line