s2t = stringIDToTypeID;
(r = new ActionReference()).putEnumerated(s2t("adjustmentLayer"), s2t("ordinal"), s2t("targetEnum"));
(d = new ActionDescriptor()).putReference(s2t("target"), r);
(d1 = new ActionDescriptor()).putEnumerated(s2t("presetKind"), s2t("presetKindType"), s2t("presetKindCustom"));
d1.putBoolean(s2t("auto"), true);
d.putObject(s2t("to"), s2t("blackAndWhite"), d1);
executeAction(s2t("set"), d, DialogModes.NO);
Save this code to a text file, change the file extension to .jsx, place the file in the Photoshop presets directory (Adobe Photoshop 2022\Presets\Scripts). After restarting Photoshop you will see this script in File->Scripts menu
Select the Black&White adjustment layer and then run the script. It will apply auto-values. If necessary, the script call can be written into an action.