I tried the solution provided in this discussion thread (Saving without dialog window) to save an image as PNG without triggering the 'Save as..' dialog. It worked perfectly on my Windows computer. However, when I shared the script with my colleague who uses a Mac, it didn't work for them. They encountered the following error:
https://i.sstatic.net/sWGdh.png
Below is the code snippet from the script:
// The saved directory location of the main master document.
Path = doc.path; // If the document is new there is no doc.path. Error is shown.
// Save the file.
var opts = new ExportOptionsSaveForWeb();
opts.PNG8 = false;
opts.transparency = true;
opts.interlaced = false;
opts.quality = 100;
opts.includeProfile = false;
opts.format = SaveDocumentType.PNG;
activeDocument.exportDocument(Path, ExportType.SAVEFORWEB, opts);
doc.close(SaveOptions.DONOTSAVECHANGES);