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

Sequential psd save script modification

Explorer ,
Jun 04, 2020 Jun 04, 2020

Copy link to clipboard

Copied

Hi
here is one script which saves psd file Sequentially . Can anyone  help me modify the script so that it could save the psd file by new name which is coppied in photoshop clipboard . I dont know where and how I should paste clipboard text. I coppied one layer name to clipboard and now I wish if this script could save the psd file by new name from clipboard text. If there is already .psd file of same name in output folder than it should save them sequentially.
Can anyone help me with this..and please dont get get angry over my english 
Script is below

#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;

};

TOPICS
Actions and scripting , Windows

Views

1.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

Community Expert , Jun 04, 2020 Jun 04, 2020

There is no need to copy the layer name to the clipboard and paste it.

 

Just use the active layer name as the source for the variable that is used to name the file. Try the following code, just select the layer that you wish the file to be named after first. The original document name will be replaced with the layer name in the incrementally numbered files.

 

 

#target photoshop
main();

function main() {
    if (!documents.length) return;
    var Name = app.activeDocument.activeLayer.name.repl
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 04, 2020 Jun 04, 2020

Copy link to clipboard

Copied

It would be easier to write a script that would save a psd with the file that would be the layer name you target before running your script. It would involve fewer steps and be less error prone.  If you go to the trouble of editing the layer name but instead copy the current name to the clipboard as text.  All you would not need a script just use saves as PSD and paste the clipboard into the name field no need to write a script. You would net as script to add a suffix that the names if the file all ready exist. The Name need not be in the clipboard. Targeting the layers and use using a shortcut wold be fewer steps and less error prone.  The script could even prompt you to enter the root file name.  Using the Active layer name be would be easier work flow but you need to be sure the Layer name will be a valid file name some characters are not permitted in file names. Also the script you posted requires this not be the first save the Root PSD is required the exist,    The get File name list will fail. It will return no file names if the root file does not exists. You would need to Add code to test if the Root PSD file exists. Like use failing the gets any files names as a signal to create the root psd file with or without a suffix,

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
Community Expert ,
Jun 04, 2020 Jun 04, 2020

Copy link to clipboard

Copied

This variation uses both the original filename and the layer name for the incremental filename save:

 

#target photoshop
main();

function main() {
    if (!documents.length) return;
    var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
    Name = Name.replace(/\d+$/, '');
    layerName = app.activeDocument.activeLayer.name.replace(/\.[^\.]+$/, '');
    combinedName = Name + "_" + layerName;
    try {
        var savePath = activeDocument.path;
    } catch (e) {
        alert("You must save this document first!");
    }
    var fileList = savePath.getFiles(combinedName + "*.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 + "/" + combinedName + "_" + 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
Community Expert ,
Jun 04, 2020 Jun 04, 2020

Copy link to clipboard

Copied

There is no need to copy the layer name to the clipboard and paste it.

 

Just use the active layer name as the source for the variable that is used to name the file. Try the following code, just select the layer that you wish the file to be named after first. The original document name will be replaced with the layer name in the incrementally numbered files.

 

 

#target photoshop
main();

function main() {
    if (!documents.length) return;
    var Name = app.activeDocument.activeLayer.name.replace(/\.[^\.]+$/, '');
    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
Explorer ,
Jun 04, 2020 Jun 04, 2020

Copy link to clipboard

Copied

LATEST
Thank you soooo much sir. This script is working perfectly and it will save lots of time. Thanks once 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