Ouch! My Mac shocked me!
Should your Mac give you a mild shock, don't worry; that just means everything is working OK.
So you've purchased your new Mac and you've set it up in your home or office, but when you touched it--it might have been the chassis or the keyboard--you got a small shock. Don't worry; you aren't tempting fate or a trip to the hospital.
While annoying, the problem here is simply a matter of static electricity, which in the amounts most people encounter is not dangerous and does not indicate a fault in the system. In this case, your body has acted like a small capacitor (similar to that in a camera flash), and over time has built a charge. When you touch the computer's case that is grounded, or if you touch a device connected to it such as a keyboard, then like setting off the camera flash you get a discharge and a small zap.
Static electricity can build up on your body for lots of reasons, including the clothes you are wearing, what items you have rubbed against or been in contact with, and atmospheric conditions such as the humidity level. Apple's computers, being made of aluminum, are highly conductive, but the same thing will happen if you touch another object that can serve as a ground or electronic "sink," including metal filing cabinets or even door jambs and handles.
Will it hurt my system?
Static discharges do have the potential to harm electronics, which is why many electronic components (motherboards, hard drives, and PCI cards) are shipped in antistatic bags; however, with an assembled system the vast majority of static discharges are grounded to the system's chassis, so provided you do not touch the inside of your system and only touch the chassis, the charges will get dissipated to earth ground instead of being routed through the system's components. This is what grounding circuits are for, and despite the annoyance of a shock, it means they are working properly.
Will it hurt me?
When you get shocked by a small static discharge, the electrical activity you feel is on the surface of your skin at the point of contact, and despite being uncomfortable will very likely not cause you any harm. If the charge were very large, you would feel more than just pain at the source of contact, and would feel its effect farther away in muscles and nerves that could result in a nonreflexive twitch or spasm (think about the effects of a taser where your whole body seizes up).
If you are concerned about the computer somehow channeling wall power to your body, then be assured this is also not happening, because the wall outlet power is high-power alternating current (AC), whereas static charge buildups are low-power and are direct current (DC) in nature. Once the static charge dissipates to ground, the charge is neutralized and the electrical activity stops.
Should the wall's AC circuit be routed through the computer, you would get not only a very large shock because of the massive 15-20 amps in most wall outlets, but the shock would be different in nature than the zap of a static discharge. In AC circuits the current first moves in one direction and then in the opposite direction at a rate of about 60 times per second. This activity acts like a pump that allows transformers to propagate current over great distances instead of needing many power stations, which is why it's used.
If this AC energy were routed into your body, then you would feel an intense vibration at a frequency of around 60Hz that would surge through your body, disrupting muscles and nerves, and burning you (or worse) before the circuit breaker trips. If you have ever heard a wall socket short out, that loud, buzzing sound before the circuit breaker trips is indicative of the alternating current in the circuit.
If the computer were shorting out an AC circuit in this manner, its delicate DC components would very likely get overloaded and break, and any shock felt would be much different than a static discharge zap. Furthermore, computer power supplies will prevent wall power from surging to the rest of the system. In laptop and Mac Mini systems the power supply that converts wall AC circuits to the DC circuit the computer uses are generally separate from the system, so any faults in it would likely result in it breaking without affecting the system. In iMac and other desktop systems this power supply is in the chassis; however, if it shorts out and breaks, then the wall circuit would still be broken instead of charging the entire chassis with wall current.
Is there any way to stop it?
When it comes to managing static discharges, there is really no way to prevent them from happening; however, you can control their prevalence a bit. Humidity helps reduce static charge buildups, so one option is to get a humidifier for your house might help. Another option is to get an ionizer to help the atmosphere in the workplace be more conductive and pull charges away from contact surfaces, including yourself.
You can also regularly ground yourself by touching large metal objects (file cabinets, fridges, or stoves), though you will likely feel a similar shock when you touch these items; however, if you are still concerned about the shocks potentially harming your system, touching another object to send the shock in that direction will dissipate it before you touch your system.