When two different materials move against each other (rubbing or simply separating) one material is more apt to hold onto electrons and the other is more apt to lose them. This causes each material to build up a charge of opposite polarity.
If one of these materials touches something else (either a different material or something of the same material), if it has a different amount of charge, the charge will try and equalize by producing a spark.
For no shock to happen when two things touch they need to have the same charge. "Grounding" tries to make everything the same voltage (things with a charge also tend to leak away this charge over time until they reach "ground" which is defined by the environment around it and is for the most part, the same). So you AND the thing have to be connected to each other (not necessarily the ground though it's a convenient sink/source for extra charge).
What part of the tool are you shocking? Circuits tend to be in cases so they can be shocked accidentally without destroying them.