Skip to main content
Known Participant
January 3, 2020
Answered

Clear Scratch Disks When Running Script

  • January 3, 2020
  • 8 replies
  • 8939 views

Hi, I'm running a script in Photoshop. The script opens lots of images (one at a time) they are quite small 2MB and performs multiple actions on each image, saving after each action.

 

My problem is that as the script runs my scratch disks fill up until eventually, they are full, this stops the script prematurely.

 

I have added an action "Edit/Purge/All" that runs each time an image has saved but this is not clearing the scratch disks, they continue to fill up.

 

Does anybody know how to empty the scratch disks while running a script, obviously without closing Photoshop?

This topic has been closed for replies.
Correct answer r-bin
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); }

 

8 replies

r-binCorrect answer
Legend
January 7, 2020
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); }

 

Kukurykus
Legend
January 8, 2020

Creating 1x1 dimension document and both 'playbackOptions' codes were not needed for me in CS6 and CC2019. I wonder whether Bee-Software doesn't need them too? btw In CS6 size of Photoshop Temp was lower before/after purge.

Legend
January 8, 2020
What do you have in mind? Without a document and its history, the command is not available.
 
Known Participant
January 7, 2020

Thanks for everybody's help with this. I've just hacked a workable solution together. 

1. I look to see if the file exists before I run the actions. This means that I can run the script a few times to create all of the images.

2. I've added more external hard drives to use as scratch drives. 

Legend
January 4, 2020
Try temporarily setting the length of the Нistory to 1 point and the size of Cache Levels to 2, or better to 1.
Also cancel the auto creation of the First Snapshot in History Options.

Run your process when your disk is guaranteed to be full.

If it helps, then in your script at the time of execution it will be possible to set such parameters.
 
Known Participant
January 5, 2020

Thanks r-bin but the same thing happens.

Legend
January 5, 2020

In this case, I would like to ask, is it really necessary to open so many files at the same time? If you use a script to process them, maybe just write to get a list of files, divide it into parts (for example, 250 files) and process each part sequentially (performing purge all after each such fragment)?

Legend
January 4, 2020
I noticed one feature.
If you call "Purge All" from a script or action, then nothing works. It works only through the menu item.

Perhaps there is a solution using something like the autohotkey program to directly call up the menu. Or do everything manually.
Have you tried doing this manually?
 
Known Participant
January 4, 2020

Hi r-bin, I'm not sure how I would do this manually while the script is running?

Legend
January 4, 2020
I didn’t think. (
I'll try to think )
 
Legend
January 3, 2020
I do not use to work with CC Photoshop.
But now I checked here such a thing on CC2018.
Created a 500x500 file.
Increased the size to 15000x15000. Applied filter Add Noise.
Did three times Ctrj + J. Selected all layers and created a smart object.
The paging file size is 7279M.
Closed the file.
The paging file size is 7279M.
Created a 500x500 file.
Did three times Ctrj + J.
The paging file size is 7279M.
Made Purge All.
The paging file size is 381M.

It seems to work. ))
 
Known Participant
January 4, 2020

Thanks for the test r-bin. I'm not saying that Purge does nothing I'm just saying that when I run my script I can see my hard drive available space falling as the script runs and eventually I get the "Scratch Disks Are Full" error. I've added Purge All to my script but unfortunately, it does not help.

 

I would have hoped that Photoshop would free up space once each file is closed. There really should be no need for Purge all. There are a lot of files but each file is only 2000px wide and there are only two files open at any time.

JJMack
Community Expert
Community Expert
January 4, 2020

Post your script perhaps someone can see a problem in it that would cause Photshop to comsume resources.

JJMack
Legend
January 3, 2020
For photoshop CS6 and below there is a registry key "ForceScratchTruncation".
If you set it to 1, then after "Purge All" the size of the scratch file is reduced. Unfortunately for CC this does not work.
Canceled?
Perhaps one of the Adobe developers will answer this question ...
 
Kukurykus
Legend
January 3, 2020

Yes, this is cancelled. I don't remember exactly where I read that, but that was about 1 - 2 years ago when Adobe employe said that after update they left visible Purge All option in menu but not working anymore.

Known Participant
January 3, 2020

Kukurkus, wow, what can I say. This would have been perfect. Adobe, why???

Simmer1
Community Expert
Community Expert
January 3, 2020

Hi,

 

Are you saving the files to an external hardrive?

Known Participant
January 3, 2020

Hi Simmer1, I have done both, saved to my local drive and external. Both have the problem.

JJMack
Community Expert
Community Expert
January 3, 2020

It sounds like you are doing some sort of Batch Process. Why do you need to keep documents open after you open a document modify the document and save an output document. You should then close nosave the document no do a  not Purge all.  Also do you suspend history stated after you open a document.  History states consume lots of resources and slow Photoshop some.  How many history stated do you keep.  If you have many documents  open and have made many changes to them I would think many open documents history states would be written to scratch space. Purge all should clear all history close not onle claers the histort it clears out the document.  If you do not need the document open for more processing after you save the output file close the document you processed.  Even small canvas document with lots of layers can consume a lot of resources. Do not fill the scratch space. In Photoshop open document images and layers are not compressed. I have processed many files and saves thousands of output files without needing to use Purge in a batch process. I'm sure my machine scratch space would have filled if I kept all the document I processed open in Photoshop. The batch took hours to run.....

 

Adobe Image Processor and  the Image Processor Pro plug-in on the web can also process image  files and run many actions on then. They do not keep all processed documents open.   Keeping all document open may well consume all your scratch space.

JJMack
Known Participant
January 3, 2020

Hi JJMack, yes each file is closed in sequence, no file is left open unnecessarily.