You need to get the material node that's attached to the object. first you should use listRelatives to get the shape node https://download.autodesk.com/us/maya/2011help/Commands/listRelatives.html then you should use listConnections to get the shading group and then again to get the material connected to the shading group…
Another thing you can use to find out how commands work is the "whatIs" mel command. This will tell you if a proceedure is a script or a embedded command. http://download.autodesk.com/us/maya/2011help/Commands/whatIs.html in the case of 'showSG' it tells me that it's a script written by the maya developers - so you can…