Alternatively - if you don't want to color everything by layer [i.e. only some objects to get their layer's color], then you can use Ruby to get the layer of the selected object[s] and then get the layer.color, from that you can make a new material [named after the layer] using that color's RGB specification, and apply that new material onto the selected object[s].
By naming the material after the layer you can test if that material has been made previously, and reuse the existing material, rather than make a new material every time...
I that's the requirement then I can easily post a code-snippet to do this...