Not sure about the code, I’ve seen that there is “shrink” method with a “selection” object but I cannot help you further as I’ve never used it.
Is it mandatory that you shrink it in the background? You can always open the document and click on the button, correct?