2011 MBA occasionally drains battery and powers down even when powered Sometimes I leave my MacBook running (connected to the charger) and when I return it has drained the battery to 0% and powered off.

This has been happening sporadically for over a year, but seems to be getting more frequent.

(Under power settings I've set it to never sleep when connected to power outlet).

Sometimes I have to turn it back on several times and each time it will power itself down within seconds to minutes.

Looking at my process list to see what is consuming CPU, there will always be some culprit.  Today it was mds (indexing Spotlight) but one other time it was the core kernel process (PID 0).

Googling suggests that occasionally the machine demands more power than the outlet can provide and borrows from the battery. If this is the case I think it is great failing that this technique does not disable itself once the battery goes into the red. 

Is there anything I can do?
First of all let me address the following:


  Googling suggests that occasionally the machine demands more power
  than the outlet can provide and borrows from the battery.


This is plain and simply false. Ignore this altogether.

Now, what almost certainly must be happening is that for some reason the MacBook is not receiving power from the charger and therefore is forced to rely on the battery instead. To clarify, what I mean is that the MacBook is drawing its power from the battery just like it would if there was a blackout, the charger was unplugged, and so on.

This indicates that you may have a faulty charger or charging cable, a faulty I/O board, or in the worst case scenario a faulty logic board.

The first thing I would try is to reset the System Management Controller (SMC).

Reset the SMC

To reset the SMC in a MacBook Air, follow these steps:


Shut down your Mac
Keep the MagSafe adapter (power cable) plugged in.
Press at the same time shiftoptioncontrol (on the left side of the built-in keyboard) and the power button
Let go
Turn your Mac back on with the power button.


Now use your MBA as normal and see if the problem returns. If so, I would be regularly keeping an eye on the charging indicator (it should always show either a green or amber light). No light means it's not delivering any power whatsoever which, assuming the mains is on and there's no blackout, indicates a hardware problem. A constant amber light (i.e. one that never goes green) also indicates a problem, usually with the battery but not always.

Run Apple Hardware Test

You can also test you Mac's main hardware components. To do this your model MBP uses Apple Hardware Test. Follow these steps:


Shut down your MacBook Pro 
Restart your MacBook Pro
Press and hold the D key before the gray startup screen appears.
After a while, Apple Hardware Test (AHT) will start.
When prompted, select your language and click the right arrow. 
When the AHT console appears, you can choose to run Basic tests by clicking the Test button. However, I suggest you select the "Perform extended testing" checkbox before you click the Test button.
Your test results will appear in the window in the bottom-right of the console.


Note 1: that the extended test will take some time. Take a note of the results and report back. 

Note 2: If pressing and holding the D key at Step 3 doesn't work, start again at Step 1 and, at Step 3 press and hold both the OptionD keys instead. This will try and run diagnostics from the internet instead, so you will need to allow more time for it to complete.