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

Script for incremental saving

Explorer ,
Sep 29, 2022 Sep 29, 2022

Copy link to clipboard

Copied

Hi everyone. I use an action where I change a placeholder image and save it, which affects 12 PSD files at once. then i use an action to save all the 12 psd in one folder, The problem is each time I save those 12 PSD into one folder, every time while running the action I've to type the "+12" number so that, they won't get override in that particular folder.

Basically, the first time I run the action for 12 PSD into one folder, they save as 1 2 3 4 to 12 file names. Now when I run the action for 2nd time I have to put 13 right? so that the files don't override. So the summary and why I'm expecting a script is, I want to somehow avoid this typing of "+12th number" each time I run the action.

Here is the action I have to repeatedly use. again and again.
attachement with the community post about script and action.png

 Optional/Addition to that: If it is possible to even change the placeholder images through the script where this will one by one take files from a particular folder that would be beyond awesome!!

TOPICS
Actions and scripting , Windows

Views

588

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 2 Correct answers

Community Expert , Sep 30, 2022 Sep 30, 2022

@Azmaeen Adil Sami 

 

You can try the following script. Don't use Automate > Batch anymore, this is a batch script. You will be prompted for an input folder and output folder.

 

Please note: you need to change the case-sensitive name of the action and action set in the script to your specific names.

 

Remove any PNG saving steps from your action, the script now does that. If required, add a save step for the updated PSD, as the script closes all PSD files without saving any changes.

 

/*

Batch 
...

Votes

Translate

Translate
Community Expert , Sep 30, 2022 Sep 30, 2022
quote

The output folder is working, for some reason, if I change the input folder destination, it's not working. 

// Select the input directory
var inputFolder = Folder('D:\Design\Product Mockups\Mockup Set 1\Set 1');


^^^^  This is what I'm putting/modifying.  


By @Azmaeen Adil Sami

 

Try removing the colon and using JS forward slashes:

 

var inputFolder = Folder('D/Design/Product Mockups/Mockup Set 1/Set 1');

 

Or using "escaped" double backslashes:

 

var inputFolder = Folder('D:\\Design\\Product Moc
...

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

@Azmaeen Adil Sami 

 

You can try the following script. Don't use Automate > Batch anymore, this is a batch script. You will be prompted for an input folder and output folder.

 

Please note: you need to change the case-sensitive name of the action and action set in the script to your specific names.

 

Remove any PNG saving steps from your action, the script now does that. If required, add a save step for the updated PSD, as the script closes all PSD files without saving any changes.

 

/*

Batch Sequential Incremental Filename to PNG.jsx

https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-for-incremental-saving/td-p/13235725
v1.1 1st October 2022 - Stephen Marsh

Based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/repeat-action-and-save-file/td-p/8532556
https://community.adobe.com/t5/photoshop/saving-sequential-file-names-of-the-same-file-to-multiple-files/td-p/12023959 

*/

#target photoshop

// Change the action and action set names to suit (Case Sensitive)
var actionName = "Molten Lead"; // Action to run
var actionSet = "Default Actions"; // Action set to run

// Disable dialog display
var restoreDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.NO;

(function () {
    
    // Select the input directory
    var inputFolder = Folder.selectDialog("Please select the input folder:");
    if (inputFolder === null) {
        // alert('Script cancelled!');
        return;
    }

    // Get the Photoshop files
    var fileList = inputFolder.getFiles(/\.(psd|psb)$/i);

    // Force alpha-numeric list sort
    fileList.sort().reverse();

    // Validate that the file list is not empty
    var inputCount = fileList.length;
    var folderSelection = (inputCount === 0);
    if (folderSelection === true) {
        inputFolder = Folder.selectDialog("No files found, please reselect the input folder:");
        return;
    }

    // Select the output folder
    var outputFolder = Folder.selectDialog("Please select the output folder:");
    if (outputFolder === null) {
        // alert('Script cancelled!');
        return;
    }

    // Start the file count saving counter at zero
    var counter = 0;

    // Loop over the input files
    while (fileList.length) {
        for (var a = 0; a < 1; a++) {
            try {
                app.open(fileList.pop());
            } catch (e) {}
        }
        app.doAction(actionName, actionSet);
        incrementalSave();
        activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        // Increment the file count saving counter for each loop
        counter++;
    }

    function incrementalSave() {
        try {
            var name = activeDocument.name;
            var n = name.lastIndexOf(".");
            if (n > 0) name = name.substr(0, n);

            // Starting number (+1), 99 would start at 100
            var indexNo = 0;

            do {
                // Zero padding file name, last number ending in 4 = 0001 or ending in 3 = 099 etc.
                var seqNo = zeroPad(indexNo + 1, 4);
                
                // Save path and filename
                var file = new File(outputFolder + "/" + seqNo + ".png");
                ++indexNo;
            }

            while (file.exists)
            var saveOptions = new PNGSaveOptions();
            // Range from 0 Largest file size to 9 smallest file size
            saveOptions.compression = 0;
            saveOptions.interlaced = false;
            app.activeDocument.saveAs(file, saveOptions, true, Extension.LOWERCASE);
            function zeroPad(n, s) {
                n = n.toString();
                while (n.length < s) n = '0' + n;
                return n;
            }

        } catch (e) {
            alert(e);
        }
    }

    // End of script notification
    app.beep();
    alert('Script completed!' + '\r' + counter + ' files saved to:' + '\r' + outputFolder.fsName);

    // Restore the dialogs
    app.displayDialogs = restoreDialogMode;

}());

 

Edit: Original code updated to v1.1

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

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 ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

thanks a lot for the script, I would love to try that, I've very little
knowledge of the language it is written, but I will try to find out how and
what needs modification to fulfill my targeted needs. Thanks again!!

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 ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

Also, every time I run the script I have to set the destination and the
source folder. can these two locations be fixed or locked? so that I don't
have to choose those two folders each time?

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 Expert ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied


@Azmaeen Adil Sami wrote:
Also, every time I run the script I have to set the destination and the
source folder. can these two locations be fixed or locked? so that I don't
have to choose those two folders each time?

 

Yes, that can be changed, you didn't mention the paths though... Using the desktop as an example:

 

Change:

 

// Select the input directory
    var inputFolder = Folder.selectDialog("Please select the input folder:");
    if (inputFolder === null) {
        // alert('Script cancelled!');
        return;
    }

 

To this:

 

    // Select the input directory
    var inputFolder = Folder('~/Desktop/png incremental save');

 

And similar for the output, changing:

 

// Select the output folder
    var outputFolder = Folder.selectDialog("Please select the output folder:");
    if (outputFolder === null) {
        // alert('Script cancelled!');
        return;
    }

 

To this:

 

    // Select the output folder
    var outputFolder = Folder('~/Desktop/png incremental save/output');

 

 

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 ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

Wow!! Amazing, You are such a lifesaver. Thanks a bunch, for giving your
valuable time to help me with this. I'm really grateful to 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
Explorer ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

The output folder is working, for some reason, if I change the input folder destination, it's not working. 

// Select the input directory
var inputFolder = Folder('D:\Design\Product Mockups\Mockup Set 1\Set 1');


^^^^  This is what I'm putting/modifying.  

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 Expert ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

quote

The output folder is working, for some reason, if I change the input folder destination, it's not working. 

// Select the input directory
var inputFolder = Folder('D:\Design\Product Mockups\Mockup Set 1\Set 1');


^^^^  This is what I'm putting/modifying.  


By @Azmaeen Adil Sami

 

Try removing the colon and using JS forward slashes:

 

var inputFolder = Folder('D/Design/Product Mockups/Mockup Set 1/Set 1');

 

Or using "escaped" double backslashes:

 

var inputFolder = Folder('D:\\Design\\Product Mockups\\Mockup Set 1\\Set 1');

 

I generally code on a Mac, so you may wish to try removing the colon.

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 ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

using "escaped" double backslashes:

 

var inputFolder = Folder('D:\\Design\\Product Mockups\\Mockup Set 1\\Set 1');

This method worked perfectly, Thanks for fixing the issue. Now everything is sorted like what I needed. Totally tried and tasted it. Many Thanks!!

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 ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

I've one little question, in which line I can change/modify the code of the starting number from where it will incrementally save the files? Right now it starts with 001, but I wanna change it to 601. 

Many thanks for the support and the script is working great how i want it to work.

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 Expert ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

quote

I've one little question, in which line I can change/modify the code of the starting number from where it will incrementally save the files? Right now it starts with 001, but I wanna change it to 601. 

By @Azmaeen Adil Sami

 

Edit: Original code updated to v1.1

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 ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

Yes, Thanks for the help you did as much you could, Let's see if this portion someone else can advice, I'm already happy to the point I got so far, with the script and automation, Thanks again!!

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 Expert ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

... Now everything is sorted like what I needed. Totally tried and tasted it. Many Thanks!!


By @Azmaeen Adil Sami

 

 

Glad to help. So the only outstanding issue is changing the file naming counter to name the first file as 601 (rather than 001), then increment it by 1 for each new file saved thereafter? 

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 ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

Yes!! It's like increments will be same as before. so that files don't
override. But i don't think i need the 601 starting anymore, cause whenever
i start the script from any point, it don't get override by the new export
in the same directory, and that was my goal, and it's working.

That's all i needed, Changing it to 601, won't be needed anymore.

But, if anyone wants to do that, we can figure that out, so that we can
start from any number we want, not just 001. (Just in case/for education)
✌️😊

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 Expert ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

I have updated the code to a 1.1 version, to clarify the filename numbering starter:

 

// Starting number (+1), 99 would start at 100
var indexNo = 0;

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 ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

Okay, let me try this one as well, to see how it goes. 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
Community Expert ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

I am getting a better understanding of the original script from which I borrowed the code, I plan to update the original code once I have tidied things up...

 

Edit: OK, I have updated the original code to a 1.1 version.

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 ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

LATEST
Wow!! Awesome, Best of luck!!

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