Copy link to clipboard
Copied
This has been asked before, but the answer the poster accepted didn't work for me. I basically need a script that just assigns a unique filename to my .PSD files, so I can just click on an action and not worry about naming the file in the "Save As" menu. It should be sequential as I'm using it to save out storyboards for animation. Thank you.
Please try this..
...#target photoshop
main();
function main(){
if(!documents.length) return;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
Name = Name.replace(/\d+$/,'');
try{
var savePath = activeDocument.path;
}catch(e){
alert("You must save this document first!");
}
var fileList= savePath.getFiles(Name +"*.psd").sort().reverse();
var Suffix = 0;
if(fileList.length){
Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));
}
Suffix= zeroPad(Suffix + 1, 4);
var saveFile
Copy link to clipboard
Copied
Please explain how file name can be random and sequential. Which do you actually want? Then waht path should thls file be saved to. If you look at the image processor script you should be able to use the code you find in there.
Copy link to clipboard
Copied
Thanks, I'll give this a try.
I guess I'm more focused on creating a unique name for a file without me having to manually type it in the "Save As" window. But for simplicity's sake, I'm going to say want sequential.
Copy link to clipboard
Copied
Also, for the path question, I'd like the first file that I save to create a new folder in my Home folder. Maybe this can be a separate script.
Thanks again for your prompt reply.
Copy link to clipboard
Copied
Please try this..
#target photoshop
main();
function main(){
if(!documents.length) return;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
Name = Name.replace(/\d+$/,'');
try{
var savePath = activeDocument.path;
}catch(e){
alert("You must save this document first!");
}
var fileList= savePath.getFiles(Name +"*.psd").sort().reverse();
var Suffix = 0;
if(fileList.length){
Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));
}
Suffix= zeroPad(Suffix + 1, 4);
var saveFile = File(savePath + "/" + Name + "_" + Suffix + ".psd");
SavePSD(saveFile);
}
function SavePSD(saveFile){
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
psdSaveOptions.layers = true;
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
};
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
};
Copy link to clipboard
Copied
Thanks! I'll give this a try.
Copy link to clipboard
Copied
This works like a beauty! Thank you so much. This will make my life so much easier. Sending good vibes to you and everyone who chimed in.
Copy link to clipboard
Copied
Hi guys,
I found this script above from SuperMerlin.
I wonder if it's possible, to modify the script, that it saves another psd-file, with continuing numbering, e.g:
Opened source file: AB_123_456.jpg
After running the script the first time:
AB_123_456-#0001.psd
Running the script again:
AB_123_456-#0002.psd
I have to mention that I'm a beginner in scripting, and this regex drives me crazy...
Thanks in advance.
Copy link to clipboard
Copied
Hello,
I tried to compile this script again, but I keep getting a "Syntax Error" message. Can someone help?