That can be scripted. However when replacing a smart object layer content you must replace the object with an object the exactly the same size and shape of the object being replaced. For there is an associated transform for every smart object layer. The transform is not replaced. The associated transform will only work correctly if the replacement is exactly like the original.
The way I get around this problem I use an alpha channel to map the size location and shape of smart placed in images where I want the images to be. So every image layer has an associated alpha channel. I place all image on top of each other in order starting directly over the required background layer.
It is relatively easy for me to replaced a placed in image if the active smart object layer. I get the the the active layer stack level relative to the bottom background layer. Using the relative number I get the alpha channel that maps that layer. I do not replace the smart object layers content I just delete the smart object layer, and place in a new image that can be and size. I size the layer to fill the bounds of the alpha channel Load the alpha channel as a selection and position the place resized image layer over the center of the selection and add the alpha channel selection as a layer mask to mask the layer to the correct shape.