Here is a working demo solution for Windows.
Checked on CC2020 win7.
You need to assign a hotkey "CtrlF8" for the menu command "Purge All".
Run the script.
It creates a large file three times in a loop and then closes it.
Before cleaning, an alert is issued so that you check the file size.
After cleaning, an alert is issued so that you check the new file size.
Each time, the size from 7GB was reduced to 300MB.
try {
for (var i = 0; i < 3; i++)
{
app.documents.add();
app.activeDocument.resizeImage(UnitValue(20000,"px"), UnitValue(20000,"px"));
for (var n = 0; n < 3; n++)
{
var d = new ActionDescriptor();
d.putEnumerated(stringIDToTypeID("distort"), stringIDToTypeID("distort"), stringIDToTypeID("uniformDistribution"));
d.putUnitDouble(stringIDToTypeID("noise"), stringIDToTypeID("percentUnit"), 12.5);
d.putBoolean(stringIDToTypeID("monochromatic"), false);
d.putInteger(charIDToTypeID("FlRs"), 652836);
executeAction(stringIDToTypeID("addNoise"), d, DialogModes.NO);
app.activeDocument.activeLayer.duplicate();
}
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
alert("Check current file")
// Purge step ///////////////////////////////////
app.documents.add(UnitValue(1,"px"), UnitValue(1,"px"));
app.activeDocument.resizeImage(UnitValue(2,"px"), UnitValue(2,"px"));
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("playbackOptions"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
var d1 = new ActionDescriptor();
d1.putEnumerated(stringIDToTypeID("performance"), stringIDToTypeID("performance"), stringIDToTypeID("stepByStep"));
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("playbackOptions"), d1);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
var file = Folder.temp.fsName + "\\" + "temp.js";
var file = new File(Folder.temp.fsName + "\\" + "temp.js");
file.encoding = "UTF8";
file.open("w");
file.write('var WshShell = WScript.CreateObject("WScript.Shell"); if (WshShell.AppActivate("'+app.activeDocument.name + ' @ '+'")) WshShell.SendKeys ("^{F8}");WshShell = null;');
file.close();
file.execute();
var d = new ActionDescriptor();
d.putEnumerated(stringIDToTypeID("state"), stringIDToTypeID("state"), stringIDToTypeID("redrawComplete"));
executeAction(stringIDToTypeID("wait"), d, DialogModes.ERROR);
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("playbackOptions"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
var d1 = new ActionDescriptor();
d1.putEnumerated(stringIDToTypeID("performance"), stringIDToTypeID("performance"), stringIDToTypeID("accelerated"));
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("playbackOptions"), d1);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
file.remove();
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
///////////////////////////////////
alert("Check file size after purge");
}
}
catch (e) { alert(e); }