import bpy

import random

#def main(context):
#    for ob in context.scene.objects:
#        print(ob)

class RandomMaterialColor(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.random_material_color"
    bl_label = "Random Material Color"

    #@classmethod
    #def poll(cls, context):
    #    return context.active_object is not None

    def execute(self, context):
        for item in bpy.data.materials:
            item.diffuse_color = (random.uniform(0.2,0.9),random.uniform(0.2,0.9),random.uniform(0.2,0.9),1)

        #main(context)
        return {'FINISHED'}


def register():
    bpy.utils.register_class(RandomMaterialColor)


def unregister():
    bpy.utils.unregister_class(RandomMaterialColor)


if __name__ == "__main__":
    register()

    # test call
    #bpy.ops.object.random_diffuse_shader()





