Thanks everyone. I also have revised this script to not work with a background layer, but rather just ensure the canvas color was set to white. Just also sharing so we all have options 
[CODE=javascript]// Open folder selection dialog
var inputFolder = Folder.selectDialog("Select a folder with images");
// Check if a valid folder was selected
if (inputFolder) {
var files = inputFolder.getFiles(/\.(jpg|jpeg|png|tif|tiff|psd)$/i);
for (var i = 0; i < files.length; i++) {
var file = files[i];
if (file instanceof File) {
open(file);
// Get the active document
var doc = app.activeDocument;
// Get original width and height
var originalWidth = doc.width;
var originalHeight = doc.height;
// Determine the new canvas size (largest dimension)
var newSize = Math.max(originalWidth, originalHeight);
// Resize the canvas to make it square (Photoshop will fill the empty space with the current background color)
doc.resizeCanvas(newSize, newSize, AnchorPosition.MIDDLECENTER);
// Save the modified image
var saveFile = new File(file.path + "/" + file.name);
var saveOptions = new JPEGSaveOptions();
saveOptions.quality = 12; // Max quality
doc.saveAs(saveFile, saveOptions, true, Extension.LOWERCASE);
// Close the document without saving additional changes
doc.close(SaveOptions.DONOTSAVECHANGES);
}
}
alert("Batch processing completed!");
} else {
alert("No folder selected. Process canceled.");
}
[/CODE]