Change Viewport Display Color of selection/collection of objects - Only changing one
It's even simpler than that ! Replace the last line with :
o.color = (0.8, 0.1, 0.0, 1)

FYI, the for loop iterates over all selected objects in the viewport, pretty straightforward.
Then the second line changes the material viewport display color. This is what you see when you set the Solid view mode to &quot;Material&quot;. Be careful though, if your object doesn't have any active material, this will throw an error and terminate the script not so gracefully.

The last line is supposed to change the object viewport color, what you see when you set the mode to &quot;Object&quot;.
Your script only takes the active object in the viewport, the one with the yellow outline. You rather want to change the color of each selected object, noted o inside the for loop.