I'm a medic and will very much simplify the process for those that do not know the anatomy and physiology.
The AED is used for someone in "cardiac arrest". That said...there are several heart rythms that are considered cardiac arrest. The only rythms that the AED 'treats' is Ventricular Fibrillation and Ventricular Tachycardiac (Vfib and V tach....AKA VF or VT). You can not tell what kind of rythm a person is in until they are "put on the monitor". The AED is the monitor in this case. The AED is designed to 'recognize' VF or VT. It will indicate "shock advised" and usually charge on its own with either of these rythms. When it is ready to shock, it will tell you and advise "press to shock". The AED is actually a SEMI automatic external defib (SAED) as you need to push a few buttons to operate it. (They tried a fully auto matic type but they had problems that made it better to just go SAED). This is the time to CLEAR the patient (no touching).
Now what is happening is this. When a heart stops, the first rythm that it is in (usually) is VT which usually degrades to VF. The organized heartbeat stops and this chaotic electrical activity is happening (VF). Think of it as the old 1950's B movie when the heroine has the hysterical episode. She is normally fine...something happens and she starts screaming. Now comes the AED (Shock). In the movie someone would usually slap her and she'd be fine again and regain her composure. The AED delivers a charge of electricity to "slap the heart". What it is actually doing is STOPPING the heart. You are hoping the heart will restart in its normal rythm. The heart still has the possibility of going back into VF. That is why defibrillation is only a STEP in care. Transfer of care to advanced life support will help prevent it from going back into VF. Advanced care also has things to help get the rythm going again...but that is a different thread.
Hope that helps. If you'd like more info let me know.