try {
var folder;
try { folder = activeDocument.path; } catch(e) { folder = new Folder(); }
var nm = activeDocument.name;
var n = nm.lastIndexOf(".");
if (n > 0) nm = nm.substr(0, n);
var file = new File (folder.fsName + "/" + nm);
file = file.saveDlg("Save As", "*.png");
if (file)
{
var d = new ActionDescriptor();
var d1 = new ActionDescriptor();
d1.putEnumerated(stringIDToTypeID("method"), stringIDToTypeID("PNGMethod"), stringIDToTypeID("quick"));
d1.putEnumerated(stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceNone"));
d1.putEnumerated(stringIDToTypeID("PNGFilter"), stringIDToTypeID("PNGFilter"), stringIDToTypeID("PNGFilterAdaptive"));
d1.putInteger(stringIDToTypeID("compression"), 9);
d.putObject(stringIDToTypeID("as"), stringIDToTypeID("PNGFormat"), d1);
d.putPath(stringIDToTypeID("in"), file);
d.putBoolean(stringIDToTypeID("copy"), true);
executeAction(stringIDToTypeID("save"), d, DialogModes.NO);
}
} catch (e) { alert(e.line+ "\n\n" +e); }