Exporting to a temporary location should be the way to go, I agree.
I’m on my way to the airport so cannot prepare you a script, but here’s one that does export programmatically, bypassing the GUI
Things changed in Slicer core since then, so you may need to adjust a few lines.
Let me know how it goes, I can be of better help tomorrow.