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.
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!!
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
...
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
...
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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');
Copy link to clipboard
Copied
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.
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.
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.
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!!
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.
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.
By @Azmaeen Adil Sami
Edit: Original code updated to v1.1
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!!
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?
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
Okay, let me try this one as well, to see how it goes. Thank you!!
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.
Copy link to clipboard
Copied