07 525xi shakes when not moving on 2007 BMW 525xi

my BMW revs up and shakes when it's idling or is sitting at a stop light or stop sign while AC is blowing. Does anyone know what could be the problem

Asked by for the 2007 BMW 525xi
Does the engine idle OK if the a/c is off? Perhaps the idle air control motor is not operating correctly when the air conditioning is on and not raising the idle speed to compensate for the additional load on the engine.Another possibility is check the compressor mounting bolts to the engine block or mounting brackets to make sure none of them are missing or have worked loose.