As @Jim says, you need to access the layer by its ' .name'
So you need something like:
Sketchup.active_model.selection.each{|e|e.material="red" if e.layer**.name**=="Bozworth"}
What I remember after trying to read through it was: 99 percent there, 1 percent tweaks and Photoshop.
The rest was lost in the mass of words.
Try summerice what you want to some simple points.