The example I gave is specific yes, based off your example, but doesn't require nurbSphere to be selected since it is specifically named in the command. The command should work with string variables in place of the shader and object names. For instance...
string $shaderName = "blinnSG";
string $objectName = "nurbsSphere";
sets -e -forceElement $shaderName $objectName;
The basic syntax here being...
sets -e -forceElement [shadingEngine] [item(s)]
As you can see assigning a shader in Maya is nothing more than putting what you want into a set. Check out the sets command for more details.
--JeffD