Select shading group, material when select object

I am quite new to mel so this seem so difficult..
I am searching for a way that when I select a object..maya will automatically select the material node that attaching to that object ... or get information about its shading node


This could help me develop to a mel that when I select an object...a window will show material of that object show I can manage material better

well.. I am not sure if this works perfectly fro you.
but try listHistory and scriptJob,
using listHistory, you can get what shading group is currently connected to your geo pretty fast.(maybe there are better ways)
and
"scriptJob" basically executes scripts while certain event is happening. I believe that there is a event called
"SelectionChanged".

Another command that might work for you is the ls command and a listConnections command... I've used this recentling in finding the number of materials assigned to the selected polygon objects. Here's the basics of what I did, you probably want to use a differnt type than mesh.

string $evalList[] = ls -selection -objectsOnly -dagObjects -exactType "mesh";
listConnections -source true -type shadingEngine $evalList;

This should return the shaders assigned to the current polygon selection per selected object... I then use the stringArrayRemoveDuplicates command to narrow this down to uniques...

If anyone has a better way of doing this, please let me know

Thanks