Well, it might be a roundabout way of getting what you want, but if you use the layer mask method, you could make the script create a selection of the layer mask or vector mask. Then you can get the bounds of the selection and apply a crop, making sure it doesn't delete the pixels. Then you could have the script remove the layer mask.
↧