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

Script to save file with random or sequential filename to be placed in action - VARIATION

Guest
Aug 16, 2017 Aug 16, 2017

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.

TOPICS
Actions and scripting

Views

4.3K

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

Guide , Aug 16, 2017 Aug 16, 2017

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

...

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 16, 2017 Aug 16, 2017

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.

JJMack

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
Guest
Aug 16, 2017 Aug 16, 2017

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.

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
Guest
Aug 16, 2017 Aug 16, 2017

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.

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 ,
Aug 16, 2017 Aug 16, 2017

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;

};

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
Guest
Aug 16, 2017 Aug 16, 2017

Copy link to clipboard

Copied

Thanks! I'll give this a try.

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
Guest
Aug 16, 2017 Aug 16, 2017

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.

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
Advocate ,
Oct 31, 2017 Oct 31, 2017

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.

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
New Here ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

LATEST

Hello,

I tried to compile this script again, but I keep getting a "Syntax Error" message. Can someone help?

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