The way to attain compunction is an attentive life. ‘The beginning of repentance comes from the fear of God and attention,’ as the holy martyr Boniface says.
Knowing the exact nature of everything, God permits each person to be tested according to his strength. As St. Paul puts it: 'God is to be trusted not to let you be tried beyond your strength, but with the trial He will provide a way out, so that you are able to bear it' (1 Cor. 10:13).
My brother, the passions are afflictions; and so the Lord does not excommunicate us because of them, but He says: 'Call upon me in the time of affliction; and I will deliver thee, and thou shalt glorify me'. Therefore, when beset by any kind of passion, there is nothing more useful than to call upon the Name of God. All we can do, weak as we are, is to flee for refuge to the Name of Jesus. For the passions, being demons, retreat if this Name is invoked.
When tested by some trial you should try to find out not why or through whom it came, but only how to endure it gratefully, without distress or rancor.
The more wood you pile on a fire the more heat you get, and thus it is with God - the more you think on Him the more you are fired with love and fervor towards Him. He who loves the Lord is always mindful of Him, and remembrance of God begets prayer.
Compunction comes when you consider how much you have grieved God Who is so good, so sweet, so merciful, so kind, and entirely full of love; Who was crucified and suffered everything for us. When you meditate on these things and other things the Lord has suffered, they bring compunction.