Here is the JSX function to do that. It is on my to do list to try to figure out how to put this into a UXP batchPlay descriptor but I haven’t attempted that yet. Based on what I read in the decriptors documentation, I think the 4 letter designators need to be switched to '$Mn ', ‘$MnIt’ and ‘$FtOn’. I’m guessing there is someway to mash this into a batchPlay descriptor.
function fitOnScreen() {
cTID = function(s) { return app.charIDToTypeID(s); };
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( cTID( 'Mn ' ), cTID( 'MnIt' ), cTID( 'FtOn' ) );
desc.putReference( cTID( 'null' ), ref );
executeAction( cTID( 'slct' ), desc, DialogModes.NO );
}