Delete all materials that aren't assigned to a face? Ok, I have several models that because various joining and un joining, have material slots that are there, but not assigned to any faces. Im exporting and would like these gone but there are too many to delete by hand:

 

Is there a script/way to get materials not assigned to a face to be eliminated?
For future landers. This works on selected objects and its using new APIs so 2.80+ only.
import bpy

objs = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
for obj in objs:
        bpy.context.view_layer.objects.active = obj
        bpy.ops.object.material_slot_remove_unused()