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

Photoshop Scripting Help Please!

Community Beginner ,
Mar 12, 2021 Mar 12, 2021

Copy link to clipboard

Copied

So, I'm new to scripting in photoshop, and want to create a script that does the folowing:

 

- Show layer 'Slate Grey'

- Export as 'FileName-Edited-SG.jpg' - (location: source folder)

- Hide layer 'Slate Grey'

 

- Show layer 'White Wash'

- Export as 'FileName-Edited-WW.jpg' - (location: source folder)

- Hide layer 'White Wash'

 

- Save as FileName-Edited.psd

 

- Close

 

How do I do this? Someone please advise if it's possible! 

 

Thanks in advance, 

Sam

TOPICS
Actions and scripting

Views

877

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 , Mar 16, 2021 Mar 16, 2021

Hi Sam, let me know how this goes:

 

/*
Photoshop Scripting Help Please!
https://community.adobe.com/t5/photoshop/photoshop-scripting-help-please/td-p/11890873
Stephen Marsh - 2021
*/

if (app.documents.length > 0) {

    var baseName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
    var docPath = app.activeDocument.path;

    selectSet(false, "Slate Grey");
    activeLayerVisibility("Shw "); // "Shw " | "Hd  "

    // var SGname = "-Edited-SG";

    // Regex create initials from layer set
...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 12, 2021 Mar 12, 2021

Copy link to clipboard

Copied

Can you post a cropped screenshot of the layers panel?


I'm presuming that the layers could be named anything? Are they always going to be only two separate words? Or do all of the files always only have two layers of the same name but different file names?

 

Is it simply a case of adding -WW or -SG (from the layer words) etc to the end of the current filename?

 

Is the original document named FileName-Edited.psd or is it FileName.psd and you want to add -Edited?

 

The workflow is known to you and obvious, however, it is not obvious to me.

 

Note: Export As and Quick Export are not accessible to scripting, which leaves save for web or save as.

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 Beginner ,
Mar 15, 2021 Mar 15, 2021

Copy link to clipboard

Copied

The first screenshot shows the layers panel for 'Filename-Edited-SG', 2nd shows the layers for 'Filename-Edited-WW'

 

I need a script that saves these two variations.with 'Edited-WW' or 'Edited-SG' on the end of the original file name.

 

Doesn't have to be Export As, I just thought it would be using that as it lets you add a suffix.

 

Need any more info let me know!

 

Screenshot 2021-03-15 at 08.45.31.png 

Screenshot 2021-03-15 at 08.45.48.png

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 ,
Mar 15, 2021 Mar 15, 2021

Copy link to clipboard

Copied

Ah, a set within a set... This is proving tougher than I first thought!

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

Hi Sam,

 

Original_File_Name.psd

Original_File_Name-Edited-SG.jpg

Original_File_Name-Edited-WW.jpg

Original_File_Name-Edited.psd

 

Is there really a need to save another PSD copy at the end of the workflow with a different name?

 

Why can't the script simply close down the original PSD without saving any changes after the two JPG files are saved? There have been no edits made to the original file, apart from turning a couple of layer set's visibility on and off.

 

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 Beginner ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

Hi Stephen,

 

Yes that would be fine, it was just so we could see what's been edited but as there's no .psd to start with it's clear anyway. If it makes it easier, just a save (with original_file_name.psd) and close would be fine.

 

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
Community Beginner ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

Easier still, just a close without saving would be fine too if it makes it easier as you say the changes made are minute.

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

It's all good, it is pretty much the same whether saving or not, I was just asking as I am laying out the saving steps in the script and the question came to me.

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

Hi Sam, let me know how this goes:

 

/*
Photoshop Scripting Help Please!
https://community.adobe.com/t5/photoshop/photoshop-scripting-help-please/td-p/11890873
Stephen Marsh - 2021
*/

if (app.documents.length > 0) {

    var baseName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
    var docPath = app.activeDocument.path;

    selectSet(false, "Slate Grey");
    activeLayerVisibility("Shw "); // "Shw " | "Hd  "

    // var SGname = "-Edited-SG";

    // Regex create initials from layer set name
    var SGname = app.activeDocument.activeLayer.name.replace(/([a-z]+[a-z]+\b ?)/g, '');
    var SG = "-Edited-" + SGname;
    var saveFileJPG = new File(docPath + '/' + baseName + SG + '.jpg');
    saveJPG(saveFileJPG);
    activeLayerVisibility("Hd  "); // "Shw " | "Hd  "

    selectSet(false, "White Wash");
    activeLayerVisibility("Shw "); // "Shw " | "Hd  "

    // var WWname = "-Edited-WW";
    
    // Regex create initials from layer set name
    var WWname = app.activeDocument.activeLayer.name.replace(/([a-z]+[a-z]+\b ?)/g, '');
    var WW = "-Edited-" + WWname;
    var saveFileJPG = new File(docPath + '/' + baseName + WW + '.jpg');
    saveJPG(saveFileJPG);
    activeLayerVisibility("Hd  "); // "Shw " | "Hd  "

    app.runMenuItem(stringIDToTypeID('selectNoLayers'));

    var saveFilePSD = new File(docPath + '/' + baseName + '-Edited' + '.psd');
    SavePSD(saveFilePSD);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    function selectSet(MkVs, setName) {
        var c2t = function (s) {
            return app.charIDToTypeID(s);
        };
        var descriptor = new ActionDescriptor();
        var list = new ActionList();
        var reference = new ActionReference();
        reference.putName(c2t("Lyr "), setName);
        descriptor.putReference(c2t("null"), reference);
        descriptor.putBoolean(c2t("MkVs"), MkVs);
        list.putInteger(30);
        descriptor.putList(c2t("LyrI"), list);
        executeAction(c2t("slct"), descriptor, DialogModes.NO);
    }

    function activeLayerVisibility(toggle) {
        var c2t = function (s) {
            return app.charIDToTypeID(s);
        };
        var descriptor = new ActionDescriptor();
        var list = new ActionList();
        var reference = new ActionReference();
        reference.putEnumerated(c2t("Lyr "), c2t("Ordn"), c2t("Trgt"));
        list.putReference(reference);
        descriptor.putList(c2t("null"), list);
        executeAction(c2t(toggle), descriptor, DialogModes.NO);
    }

    function SavePSD(saveFilePSD) {
        psdSaveOptions = new PhotoshopSaveOptions();
        psdSaveOptions.embedColorProfile = true;
        psdSaveOptions.alphaChannels = true;
        psdSaveOptions.layers = true;
        psdSaveOptions.annotations = true;
        psdSaveOptions.spotColors = true;
        activeDocument.saveAs(saveFilePSD, psdSaveOptions, true, Extension.LOWERCASE);
    }

    function saveJPG(saveFileJPG) {
        var jpgOptions = new JPEGSaveOptions();
        jpgOptions.formatOptions = FormatOptions.STANDARDBASELINE;
        jpgOptions.embedColorProfile = true;
        jpgOptions.matte = MatteType.NONE;
        jpgOptions.quality = 12;
        app.activeDocument.saveAs(saveFileJPG, jpgOptions, true, Extension.LOWERCASE);
    }

}

else {

    alert('A document must be open to use this script!');

}

 

It is not what I originally planned, however, it should get the job done.

 

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
Community Beginner ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

Fantastic, thank you. Really appreciate your efforts!

 

I'm going to try it now to see if it works.

 

Sam

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 Beginner ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

LATEST

Legend! All works as intended.

 

Thanks mate.

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