• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Clear Scratch Disks When Running Script

Community Beginner ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

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?

TOPICS
Actions and scripting

Views

5.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Jan 07, 2020 Jan 07, 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();
    
        ap
...

Votes

Translate

Translate
Adobe
Community Beginner ,
Jan 04, 2020 Jan 04, 2020

Copy link to clipboard

Copied

Thanks r-bin but the same thing happens.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 04, 2020 Jan 04, 2020

Copy link to clipboard

Copied

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)?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 05, 2020 Jan 05, 2020

Copy link to clipboard

Copied

Hi Dmitry, I don't open all of the files at the same time. I open two files at a time, I then close these files and then I open the next two... This is why I am puzzled as to why the scratch drives fill up. 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

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); }

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

What do you have in mind? Without a document and its history, the command is not available.
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

Yes that is right. When you do it manually then Purge All (and other options) are not avialable in Edit menu. But as continuation of script they are still avialable. So when doing it manually you have to create 1x1 (or other dimension) document in fact, but via script that step is not needed.

 

I don't know how I did that worked, but that is not true, what I tested now 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

Without playbackOptions, keystrokes will not reach Photoshop.
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

For some reason without playback options (so when it's not in step-by-step mode but still in accelerated) it worked for me, I mean triggered Ctrl F8 shortcut by vbs script.

 

It only didn't use shortcuts (regardless of playback mode was used) while trying to ran it from ESTK, but when saved to .jsx file and ran as script from Ps it worked.

 

EDIT: In CS6 it doesn't purge cache at all (with or without playback). In CC 2019 your script works (also without playback).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 18, 2022 Mar 18, 2022

Copy link to clipboard

Copied

Hi r-bin, or anyone else. Does this code replace the 'Purge all' type line that I have in my current java script? I'm trying to figure out how to implement your code. Do I run your code after I've run my other code? I'm doing data-sets, so after a data set completes and saves out, I'd run your code and it does its thing? Sorry I don't write javascript, I borrow. 

 

Thank you,

Ian

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 12, 2023 Dec 12, 2023

Copy link to clipboard

Copied

I'm currently using Photoshop 24.7.1 and the default keyboard shortcuts doesn't appear to include Ctrl+F8 for Edit > Purge > All.

Upon making that change, the script does appear to still work.

 

Another potential issue is that executing the temp.js doesn't necessarily run it in Photoshop. My default app was to open it in VS Code, so that's initially what happened during runtime.

 

FYI I also tested scriptlistener code for doing this command directly instead of through a simulated key press, but appears to have no effect. If anyone knows how to improve on it, that would be much appreciated.

var purgeDesc = new ActionDescriptor()
purgeDesc.putEnumerated(ch("null"), ch("PrgI"), ch("Al  "))
executeAction(ch("Prge"), purgeDesc, DialogModes.NO)

function ch(a) { return charIDToTypeID(a) }

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

Have you solved the problem at present? Do you have any new plans?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 29, 2024 Apr 29, 2024

Copy link to clipboard

Copied

Sorry for the late reply. No I have not found a perfect solution. My team landed on deleting the temp file directly when it is not in use by the app.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 29, 2024 Apr 29, 2024

Copy link to clipboard

Copied

LATEST

okay, thank you

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines