Script to place Logos in different phones cases in Photoshop

Explorer ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Hello everyone ,   to start i want to point out that i have no knowledge of scripting just wondering if any of you can help. i am using so far actions but i guess they're so limited even when using conditions.  

 

For my case i want to make a script that i can place a logo design over a phones cases (iphones cases for examples) i was able to make an "action" to place the designs but i have a small problem is that in some of the phones cases there's diffrent holes and different shapes and sizes so the "move and place" won't work in such a case, i want to make a condition at least by jpeg numbers, when it reach the 13 images excute this condition instead, that's the least that i can think off, i have attached an example of many please check it.

 

thank you in advance for your help !

TOPICS
Actions and scripting , Windows

Views

4.8K

Likes

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

Adobe Community Professional , May 01, 2020 May 01, 2020
The following code example presumes that a folder of input files have a hyphen - delimiter with variable case-sensitive text, such as a colour name: myfile-RED.psd myfile-GREEN.psd myfile-BLUE.psd An action corresponding to the specified matching portion of the filename would then be applied, overwriting the original files. I have surrounded each condition in comments clearly identifying each code block so that you can easily copy/paste them to create additional conditions. You will obvi...

Likes

Translate

Translate
LEGEND ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

You only show one design. If all your designs are the same aspect ratio what you need to do is create mock ups for each phone case. And have smart objects logo layers that are transformed and warped for each case then the cases can be populated by a batch populating script. The smart object layer can be masked so that the case holes will not get any logo information in them. However, the logo needs to be warped  to avoid the holes and maintain its contents.  The Logo in your example would be better done using two smart object layers one for the graphic image that when  masked would  have holes punched by the layers mask. The Second smart object layer for the text. So that can be located independently from the graphic. You problem is  related to the text placement.  You basically want two objects that  have two aspect aspect ratios a more or less square aspect ratio for  the graphoc and a rectangle area for the text.  Each smart Object has an associated object transform.  So each mock up can size, rotate, position and warp the layers object. Additionally smart filters can be also added. You just want two standard size objects in your templates. So a script can replace their content by either using Replace content or editing the standard size object and fitting the replacments.  The Smart Object layer's  object transform will takes care of the rest for the mock ups.  The transforms do not change. So the Object will be sized, rotated, position and warped for each mock up you populate the way you created the mocksups for your two standard size opjects.

 

 

JJMack

Likes

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 ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Hi JJMack; Thank you for responding to my post, yes the main problem in this scenario is the text it self, that's why i have opened this post, so if i can know the basics how to manipulate the text and move according to the phone shape and holes i can apply the same thing for any other design, this is not a mockup of a full background applied on the case but a design to be placed so it's complicated i guess for me to create conditions, if it's a background it would be easy using the smart object as you suggested, so how can i solve this particular problem thanks.

Likes

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
LEGEND ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Have you tried searching this forum.  Do you actually think your are the first person to have a question like yours. There are many threads on products mockups. What did you not understand about what I wrote?

Capture.jpg

 

image.png

JJMack

Likes

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 ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

yea sorry i totally searched in the forum what i am at so far and what i have found that i think it's a good way to solve this is by creating a script with conditions relating to the image name and by the specific name of the image i can run different actions, actually i have found your code right in this forum i have tried it so many times and manipulated but nothing happened when triting to load it 

#target photoshop

app.bringToFront();

function main(){

   if(!documents.length) return;

   for (var i=0;i<documents.length-1;i++) { // for the open document

      app.activeDocument = documents; // switch active document

      if (app.activeDocument.name.indexOf("-4LP.") != -1 ){doAction("Create4LP","actionsetName");}

      if (app.activeDocument.name.indexOf("-3P.") != -1 ){doAction("Create3P","actionsetName");}

}

}

i am sorry again cause i am more to designing then coding and thanks in advance.

Likes

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 ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

And for your suggestion to create a mockup for every case, there're like over 400 cases i had to deal with, it's really a long effort to do, so i hope you tell me how to make your code work by adding the open files and the save i guess they're missing, plus i was searching and i have found this tutorial with the code but it's really to complicated to change it for my own requirements, i am hopping that you can help me i will really appreciate it thanks

Likes

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
LEGEND ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

You have 400 cases. You need to deal with 400 products mock ups. There is no way around that IMO for cases differ.  The mock ups for each product differs only in some minor way. In general cases are the same.  They are rectangle cases with Cast details.  Cutouts, Body paint, Design graphic, Design text.  There is not much that differs.  It is very easy to create a general prototype template. and duplicated it for each case and then customize then duplicated mock up for a particular case. Then have a single script Populate all your designs into all the mocks a single batch run. 

 

I found it quite easy.  I wrote the scripts last year,   I create a Phone Prototype mock up in about an hour.  Copy Paste rename of the mock up takes  less than a minutes.  Replacing the Case Layer, Changing the Group Case layer mask and modifying the Graphic and Text Smart object transforms an additional minute or two.  What takes the time is creating the replacement Case layers and the designs for each case items, Paint, Graphic, Text. I see no way around that.

image.png

Here is the Prorotype mock psd.

image.png

Here is a customizes duplicate

Capture.jpg

 

An output jpeg

text2 Phone1.jpg

 

There is no need to write a scipt if the mockup templates are designed to be easy to update. Scripts exist to batch populated them.   Free Photo Collage and Mockup Toolkit 

JJMack

Likes

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 ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

JJMack, thanks for you effort i really appreciate it, it's just that it's not the way that the job should be finished, as you said you spent about an hour for one single mockup, but what i am suggesting it's a really easy and smooth way to achieve that with just a single lines of script, i know if it's easy why i shouldn't do it, well i am really poor at scripting knowledge, that's why i am here asking, i already work on the actions i just want a script to launch those actions depends on the files names that's all and save them. and one more thing if you still have your example template can you share it with me if it's possible and you have no problem along with the script thanks in advance.

Likes

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
LEGEND ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

No scripting is required no actions are required when using mockup.  Just Mockup PSD files and design replacement files are required.  The Scripting tutorial you posted is for a much different type of processing. More a color paint process.  Their process has many PNG file many more or less  were alpha channel types of selection for the their image scans. Their script select some of the png files and stacked these as a layered a document.  Then used an Action set that  had action for colors.  The actions would the use these stack scams to somehow to create a colored image. So they had one script that selected and stacked png based one some naming convention and a set of actions to convert the staked layers into their colored images. 

image.png

The action set was not included is the download Have nor Idea what the actions did.  The script logged what it found and stacked.

 

13:49:01 >>>>> Log file created.
13:49:02 >>>>> Files found. Starting postproduction
13:49:02 >>>>> _____________________________
13:49:02 >>>>> Found GardenChair_L-100_W-69_color-.RGB_color.0000.png
13:49:02 >>>>> Found GardenChair_L-100_W-69_color-.Alpha.0000.png
13:49:02 >>>>> Found GardenChair_L-100_W-69_color-.VRayObjectSelect_alpha.0000.png
13:49:02 >>>>> Found GardenChair_L-100_W-69_color-.VRayWireColor.0000.png
13:49:06 >>>>> Running action: transparent
13:49:07 >>>>> _____________________________
13:49:07 >>>>> Found GardenChair_L-100_W-69_color-.RGB_color.0001.png
13:49:07 >>>>> Found GardenChair_L-100_W-69_color-.Alpha.0001.png
13:49:07 >>>>> Found GardenChair_L-100_W-69_color-.VRayObjectSelect_alpha.0001.png
13:49:07 >>>>> MISSING! GardenChair_L-100_W-69_color-.VRayWireColor.0001.png
13:49:07 >>>>> Skippin process for GardenChair_L-100_W-69_color-.RGB_color.0001.png
13:49:07 >>>>> _____________________________
13:49:07 >>>>> Found GardenChair_L-100_W-69_color-.RGB_color.0002.png
13:49:07 >>>>> Found GardenChair_L-100_W-69_color-.Alpha.0002.png
13:49:07 >>>>> Found GardenChair_L-100_W-69_color-.VRayObjectSelect_alpha.0002.png
13:49:07 >>>>> Found GardenChair_L-100_W-69_color-.VRayWireColor.0002.png
13:49:12 >>>>> Running action: terracotta
13:49:13 >>>>> _____________________________
13:49:13 >>>>> Found GardenChair_L-100_W-69_color-.RGB_color.0003.png
13:49:13 >>>>> Found GardenChair_L-100_W-69_color-.Alpha.0003.png
13:49:13 >>>>> Found GardenChair_L-100_W-69_color-.VRayObjectSelect_alpha.0003.png
13:49:13 >>>>> Found GardenChair_L-100_W-69_color-.VRayWireColor.0003.png
13:49:18 >>>>> Running action: lightgreen
13:49:30 >>>>> _____________________________
13:49:30 >>>>> Found GardenChair_L-100_W-69_color-.RGB_color.0004.png
13:49:30 >>>>> Found GardenChair_L-100_W-69_color-.Alpha.0004.png
13:49:30 >>>>> Found GardenChair_L-100_W-69_color-.VRayObjectSelect_alpha.0004.png
13:49:30 >>>>> Found GardenChair_L-100_W-69_color-.VRayWireColor.0004.png
13:49:35 >>>>> Running action: paleblue
13:49:36 >>>>> _____________________________
13:49:36 >>>>> Found GardenChair_L-150_W-69_color-.RGB_color.0000.png
13:49:36 >>>>> Found GardenChair_L-150_W-69_color-.Alpha.0000.png
13:49:36 >>>>> Found GardenChair_L-150_W-69_color-.VRayObjectSelect_alpha.0000.png
13:49:36 >>>>> Found GardenChair_L-150_W-69_color-.VRayWireColor.0000.png
13:49:41 >>>>> Running action: transparent
13:49:42 >>>>> _____________________________
13:49:42 >>>>> Found GardenChair_L-150_W-69_color-.RGB_color.0001.png
13:49:42 >>>>> Found GardenChair_L-150_W-69_color-.Alpha.0001.png
13:49:42 >>>>> Found GardenChair_L-150_W-69_color-.VRayObjectSelect_alpha.0001.png
13:49:42 >>>>> Found GardenChair_L-150_W-69_color-.VRayWireColor.0001.png
13:49:47 >>>>> Running action: chamomile
13:49:49 >>>>> _____________________________
13:49:49 >>>>> Found GardenChair_L-150_W-69_color-.RGB_color.0002.png
13:49:49 >>>>> Found GardenChair_L-150_W-69_color-.Alpha.0002.png
13:49:49 >>>>> Found GardenChair_L-150_W-69_color-.VRayObjectSelect_alpha.0002.png
13:49:49 >>>>> Found GardenChair_L-150_W-69_color-.VRayWireColor.0002.png
13:49:53 >>>>> Running action: terracotta
13:49:54 >>>>> _____________________________
13:49:54 >>>>> Found GardenChair_L-150_W-69_color-.RGB_color.0003.png
13:49:54 >>>>> MISSING! GardenChair_L-150_W-69_color-.Alpha.0003.png
13:49:54 >>>>> Found GardenChair_L-150_W-69_color-.VRayObjectSelect_alpha.0003.png
13:49:54 >>>>> Found GardenChair_L-150_W-69_color-.VRayWireColor.0003.png
13:49:54 >>>>> Skippin process for GardenChair_L-150_W-69_color-.RGB_color.0003.png
13:49:54 >>>>> _____________________________
13:49:54 >>>>> Found GardenChair_L-150_W-69_color-.RGB_color.0004.png
13:49:54 >>>>> Found GardenChair_L-150_W-69_color-.Alpha.0004.png
13:49:54 >>>>> Found GardenChair_L-150_W-69_color-.VRayObjectSelect_alpha.0004.png
13:49:54 >>>>> Found GardenChair_L-150_W-69_color-.VRayWireColor.0004.png
13:49:59 >>>>> Running action: paleblue
13:50:00 >>>>> Postproduction is ready, check the /_generated folder for output and logs

 

 

JJMack

Likes

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 ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

Well thanks again for all your efforts, but i maybe didn't clear something this is a project to be fair, and i am asked to provide a script for it, so the mockups solution i was going to give it a try but the thing is that it needs a manual replacement and it's like semi-Automated at best.

for the youtube video i know it's different and it's much complicated but it's basically having the same shema that i am trying to acheive by fetching through the files name and doing actions for that particular file name plus an extra copy and paste, i was able to change the code to fetch for the name for example "Black color" but that was my limit as i couldn't remove the copy and paste of the channels and the script was starting to give me errors before continuing to the stage of the action excution.

Likes

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
LEGEND ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

The thing is you do not seem to have much knowledge about scripting languages and Adobe Scripting DOM, Adobe Action managers code and Adobe Photoshop plug-in Scriptlistener.

 

I have to admit the I only hack at Photoshop Scripting.  I can not claim toe be good at it.  I do not know JavaScript but I do have some a programming history.  One day my manager ripped my business machine repair tool bag from my hands and anointed me a Programmer. Handing me a green card, a book 360 principles of operations and a manual IBM 360 assembler language. For the next 36 years that remained my title at IBM "programmer". I retired at the end of 2002.   

 

I also have some Photoshop knowledge I  have been using it since 1993. So I don't understand why you would want a manual operation if you need to produce a large number of product images with different design element.  That seems like a huge wast of time.

JJMack

Likes

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
Adobe Community Professional ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

"... i already work on the actions i just want a script to launch those actions depends on the files names that's all and save them."

 

If you simply wish to run a specific action when a specific filename is found, then this script might help:

 

siva.png

 

SIVA'S PHOTOSHOP CONDITIONAL ACTION

Download Siva's Photoshop Conditional Action

Likes

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 ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

Hi Stephe, thanks for your replay, i already found your code when was exploring the internet and this forum, but your script is limited so i have to open it each time and do everything manually, how can turn it to choose multiple threads thanks.

Likes

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
Adobe Community Professional ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

A semi-automated approach is better than nothing, right? :]

Likes

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
Adobe Community Professional ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

The following code example presumes that a folder of input files have a hyphen - delimiter with variable case-sensitive text, such as a colour name:

 

myfile-RED.psd

myfile-GREEN.psd

myfile-BLUE.psd

 

An action corresponding to the specified matching portion of the filename would then be applied, overwriting the original files.

 

I have surrounded each condition in comments clearly identifying each code block so that you can easily copy/paste them to create additional conditions.

 

You will obviously need to change the name of the action and action set.

 

This script overwrites the originals, so work on copies.

 

 

/*

Batch Play Actions from Conditional Filename Parts.jsx

https://community.adobe.com/t5/photoshop/script-to-place-logos-in-diffrent-phones-cases-in-photshop/m-p/11098559
Script to place Logos in diffrent phones cases in Photshop

The following code example presumes that a folder of input files have a hyphen - delimiter with variable case-sensitive text, such as a colour name:

myfile-RED.psd
myfile-GREEN.psd
myfile-BLUE.psd

An action corresponding to the specified matching portion of the filename would then be applied, overwriting the original files.

The indexOf method is case sensitive:
    if (app.activeDocument.name.indexOf('-RED') != -1) {

An alternative is to use a case insensitive regular expression based match:
    if (app.activeDocument.name.match(/-RED/gi) != null) {

*/

#target photoshop
app.bringToFront();

if (!documents.length) {

    var savedDisplayDialogs = app.displayDialogs;

    var inputFolder = Folder.selectDialog('Select the input folder', '');
    var inputFiles = inputFolder.getFiles();

    app.displayDialogs = DialogModes.NO;

    for (var a = 0; a < inputFiles.length; a++) {
        try {
            var inDoc = open(inputFiles[a]);

            // Start doing stuff

            /* CONDITION #1 */
            if (app.activeDocument.name.indexOf('-RED') != -1) {
                app.doAction('Red Action', 'Change Colour Action Set'); // Change action & action set name
                /* CONDITION #1 */

                /* CONDITION #2 */
            } else if (app.activeDocument.name.indexOf('-GREEN') != -1) {
                app.doAction('Green Action', 'Change Colour Action Set'); // Change action & action set name
                /* CONDITION #2 */

                /* CONDITION #3 */
            } else if (app.activeDocument.name.indexOf('-BLUE') != -1) {
                app.doAction('Blue Action', 'Change Colour Action Set'); // Change action & action set name
                /* CONDITION #3 */

            } else {
                /* DO SOMETHING ELSE */
            }

            app.activeDocument.close(SaveOptions.SAVECHANGES);

            // Finish doing stuff

        } catch (e) {
            continue;
        }
    }

    app.displayDialogs = savedDisplayDialogs;
    alert('Script completed!' + '\n' + 'Files saved to:' + '\n' + inputFolder.fsName);

} else {
    alert('Please close all open files before running this script');
}

 

 

Likes

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 ,
May 02, 2020 May 02, 2020

Copy link to clipboard

Copied

Wow thank you so much Stephen,  i really have no words to say, it really works, excuse me if am going to ask you one last thing, the script is saving my work as a PSD and it is asking me everytime where to save, can you tell me how to edit the script so that i save in specific format for my example here it's a Jpeg and how to add a line of code to ask me to choose a file where to save or create one automatically as it's asking me at the beggining, i am know that i am exaggerating but is there a way to add words to the image files names for example my original file name is "Iphone 5 red" and at the end of the script it will add 'liberty statue' so i it will be "Iphone 5 red liberty statue"thanks you so much in advance.

Likes

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
Adobe Community Professional ,
May 02, 2020 May 02, 2020

Copy link to clipboard

Copied

The original script was more of a proof of concept than anything, I expected it to require fine tuning.


Yes, it is possible to save into a different format, such as JPEG. Save as or save for web? What options?

 

It is possible to save to a specific location. Do you want to pick an output folder? Or do you want the script to make a new output folder inside the input folder? What name and where would the name come from?

 

It is also possible to modify the input name with a prefix or suffix at output. I presume that this name would be variable and not fixed/static. Where would it come from? The file itself? From the action or action set in use? By typing into a dialog? From the save folder name?

Likes

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 ,
May 02, 2020 May 02, 2020

Copy link to clipboard

Copied

for the Jpeg saving i have found a lines of code:

saveJpeg(outputFilename, outputFolder, 12);

target.resizeImage(800, 600);

saveJpeg('LQ_' + outputFilename,outputFolder, 6);

but they won't work when i try to paste to the script, so i want to have a code saveJpeg and i add the options if possible like quality 12 or 10 or any quality number the save needs to be done automatically not everytime i have to click yes save as Jpeg thanks.

 

Well i think it's better to create a folder where the original files are auto like "Final rendering" or "Generated" anything, or to ask me where do i want to save the files, so is it possible that i can have both codes? thanks

 

well for my case the name comes from the design logo that's been added to the cases, cause my actions are made like this {open the design from the directory where the cases images are there's a folder called design goes here,  then it will add it to the case and place it over it with some alignement}, so is it possible to pop up a window to ask where to add a name one time and apply it to all or in the code it self to add the design name; so if it's possible to have both i will try to switch between them and thank you so much again.

Likes

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
Adobe Community Professional ,
May 02, 2020 May 02, 2020

Copy link to clipboard

Copied

"Well i think it's better to create a folder where the original files are auto like "Final rendering" or "Generated" anything,"

Yes, but where? A new folder inside the source folder? In order to automate, one needs to know the destination. This is not clear to me.

 

"well for my case the name comes from the design logo that's been added to the cases"

Is this the name of the input folder? In order to automate, one needs to know the source. This is not clear to me.

 

______________

 

Please try this revised code and let me know how it works for you.

 

This version adds a dialog window to select an output folder and uses Export/Save for Web to save to JPEG quality 70%, it is easy to change this in the code to another quality % level. There is an option to convert to sRGB which is not active, just remove the opening /* and closing comments */ to enable. A prompt will also ask for the suffix to add to the input filename, for example a suffix of "mySuffix" added to the input name of "myFile.psd" would be saved as "myFile_mySuffix.jpg" (the underscore delimiter is hardcoded and should not be included in the suffix).

 

 

/*

Batch Play Actions from Conditional Filename Parts - Prompt for Suffix and JPEG Save Location.jsx

Changelog:
2nd May 2020 - Initial Release
3rd May 2020 - Added interactive JPEG save & suffix prompts

https://community.adobe.com/t5/photoshop/script-to-place-logos-in-diffrent-phones-cases-in-photshop/m-p/11098559
Script to place Logos in diffrent phones cases in Photshop

The following code example presumes that a folder of input files have a hyphen - delimiter with variable case-sensitive text, such as a colour name:

myfile-RED.psd
myfile-GREEN.psd
myfile-BLUE.psd

An action matching the specified matching portion of the filename would then be applied, overwriting the original files.

The indexOf method is case sensitive:
    if (app.activeDocument.name.indexOf('-RED') != -1) {

An alternative is to use a case insensitive regular expression based match:
    if (app.activeDocument.name.match(/-Red/gi) != null) {

*/

#target photoshop
app.bringToFront();

(function () {

    if (!documents.length) {

        var savedDisplayDialogs = app.displayDialogs;

        var inputFolder = Folder.selectDialog('Select the input folder:', ''); // Optionally add a default directory
        if (inputFolder == null) {
            return
        }; // Test if cancel returns null, then do nothing.

        var outputFolder = Folder.selectDialog('Select the JPEG output folder:', ''); // Optionally add a default directory
        if (outputFolder == null) {
            return
        }; // Test if cancel returns null, then do nothing.

        var suffix = prompt('Enter the suffix to append:', '');
        if (suffix == null) {
            return
        }; // Test if cancel returns null, then do nothing.
        if (suffix == "") {
            return
        }; // Test if an empty string is returned, then do nothing.
        /* https://prepression.blogspot.com/2019/03/bridge-batch-rename-to-clean-invalid.html */
        var suffixCleansed = suffix.replace(/[^-_0-9a-zA-Z]/gi, '');

        var inputFiles = inputFolder.getFiles(/\.(jpg|jpeg|tif|tiff|psd|psb|eps|png|bmp|gif)$/i); // Add or remove as required

        app.displayDialogs = DialogModes.NO;

        for (var a = 0; a < inputFiles.length; a++) {
            try {
                var inDoc = open(inputFiles[a]);

                // START DOING STUFF

                    /* CONDITION #1 */
                if (app.activeDocument.name.indexOf('-RED') != -1) {
                    app.doAction('Red Action', 'Change Colour Action Set'); // Change action & action set name
                    /* CONDITION #1 */

                    /* CONDITION #2 */
                } else if (app.activeDocument.name.indexOf('-GREEN') != -1) {
                    app.doAction('Green Action', 'Change Colour Action Set'); // Change action & action set name
                    /* CONDITION #2 */

                    /* CONDITION #3 */
                } else if (app.activeDocument.name.indexOf('-BLUE') != -1) {
                    app.doAction('Blue Action', 'Change Colour Action Set'); // Change action & action set name
                    /* CONDITION #3 */

                } else {
                    /* DO SOMETHING ELSE */
                }

                var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
                var saveFileJPEG = new File(outputFolder + '/' + docName + '_' + suffixCleansed + '.jpg');
                SaveForWeb(saveFileJPEG);

                app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

                // FINISH DOING STUFF

                // JPEG S4W Options
                function SaveForWeb(saveFileJPEG, jpegQuality) {
                    /*
                    // Convert to sRGB Step
                        if (app.activeDocument.colorProfileName.substring(0, 4) != "sRGB")
                        app.activeDocument.convertProfile("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, false); // BPC, Dither
                    */
                    var sfwOptions = new ExportOptionsSaveForWeb();
                    sfwOptions.format = SaveDocumentType.JPEG;
                    sfwOptions.includeProfile = true;
                    sfwOptions.optimized = true;
                    sfwOptions.quality = 70;
                    activeDocument.exportDocument(saveFileJPEG, ExportType.SAVEFORWEB, sfwOptions);
                }

            } catch (e) {
                continue;
            }
        }

        app.displayDialogs = savedDisplayDialogs;
        alert('Script completed!' + '\n' + inputFiles.length + ' files saved to:' + '\n' + outputFolder.fsName);

    } else {
        alert('Please close all open files before running this script');
    }
})();

 

 

Likes

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 ,
May 03, 2020 May 03, 2020

Copy link to clipboard

Copied

Is this the name of the input folder? In order to automate, one needs to know the source. This is not clear to me.

 

check this, this is where the action take the design image png (from the folder Design goes here) to add it to the cases

Capture.PNG

for this example the name of the design is Design so that will be added to the output cases names example: 'Condor 5 Clear Design.jpeg'

qsdqsd.PNG

I was going to ask you how to make the script fetch the name from the whole image name but as i did tests and put the word in the start of the image name in the middle mixed it with other names and it's totally working and finding the name wherever it is in the image name that's really cool.

 

I already chose your respond as a correct one, you have answer all my queries and even more, you really have made my day and my Exam test, i really don't know how to thank you, thank you so much.

 

One last thing if you excuse me are you the one who made this script if so i hope you give me some refferences that you used to start writting scripts i am willing to start with this domain thanks.

Likes

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
Adobe Community Professional ,
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

Yes, I made the script, in a similar way that Dr Frankenstein made his creation. An original bit here, a borrowed bit there etc. All the bits stuck together to create a whole, but perhaps not as clean or pretty as a natural birth! I tend to reuse previous code a lot and have a library of snippets for general reuse. Sadly I spend more time debugging and trying to work out why I have broken something that used to work in a similar but different context.

 

I found that it was very hard for me to study and learn 'generic' JavaScript with no specific goal apart from learning JavaScript... So participating in discussion threads such as this gives me a much better way to learn.

 

As for learning resources, Adobe docs/guides, these forums, internet searches and the W3C site are my usual resources.

 

After 2 years or so of playing with scripting, I'm still a beginner, just a little less green than when I started. I have been using Photoshop since the early 1990's (before layers were introduced) and have a lot of experience with creating actions, which helps.

 

Good luck!

Likes

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 ,
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

1990 Wow! i was not even born yet.

 

One last thing Stephen, did you figure out how to make the suffix taken from the original name of the Design added? if you don't know please don't waste your time with this, as you already gave me much to finish my test and my work, just was asking so maybe it can benefit me in many things in the future as retreiving the data from certain places.

 

Yea same thing about the motivation for me i had and yet have no motivation for learning programming and scriptting, that happened to me with designing i can assure you that without the motivation to help my family with there stuffs, i would have never entered the Design Domain, so same thing applied to this yet because of  what i was struggling with and made me open this topic, it made me look again in the scripting community since i was making everything manually for things that i could've saved a lot of time and effort, so thank you for spending the time to help me and even make me the whole script by your own effort and time, i wish you the best luck on whetever you're in now, and i hope you're staying safe.

Likes

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
Adobe Community Professional ,
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

Well "it should be easy" (famous last words), however, I would need one or more very clear examples...

 

You showed a folder called "Design goes here". If this was the name you wanted to use as the suffix, then it would be possible to use the whole folder name "Design goes here" or just part of the name such as "Design".

 

I'm really not sure where/what the suffix comes from.

 

 

Likes

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 ,
May 05, 2020 May 05, 2020

Copy link to clipboard

Copied

LATEST

No i have explained to you above i hope you check it, that's just the folder that contain the design when you open it you will find the design and with in it there's the design for the examples it's the domino design and the name of the domino design is "Design .png" so that's the suffix the word (Design ) so the file contain the suffix not the folder thanks.

Likes

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
Adobe Community Professional ,
May 03, 2020 May 03, 2020

Copy link to clipboard

Copied

This variation on the previous script will automatically save the JPEG files to a sub-folder titled "Processed Mockups" in the source/input folder using an interactive prompt for the suffix.

 

 

/*

Batch Play Actions from Conditional Filename Parts - Save JPEG to Source Sub-Folder.jsx

Changelog:
2nd May 2020 - Initial Release
3rd May 2020 - Added interactive suffix prompt and JPEG save to sub-folder in input folder

https://community.adobe.com/t5/photoshop/script-to-place-logos-in-diffrent-phones-cases-in-photshop/m-p/11098559
Script to place Logos in diffrent phones cases in Photshop

The following code example presumes that a folder of input files have a hyphen - delimiter with variable case-sensitive text, such as a colour name:

myfile-RED.psd
myfile-GREEN.psd
myfile-BLUE.psd

An action matching the specified matching portion of the filename would then be applied, overwriting the original files.

The indexOf method is case sensitive:
    if (app.activeDocument.name.indexOf('-RED') != -1) {

An alternative is to use a case insensitive regular expression based match:
    if (app.activeDocument.name.match(/-Red/gi) != null) {

*/

#target photoshop
app.bringToFront();

(function () {

    if (!documents.length) {

        var savedDisplayDialogs = app.displayDialogs;

        var inputFolder = Folder.selectDialog('Select the input folder:', ''); // Optionally add a default directory
        if (inputFolder == null) { return }; // Test if cancel returns null, then do nothing.  

        var outputFolder = new Folder(decodeURI(inputFolder) + '/Processed Mockups'); // Change name, retain the leading / forward slash
        if (outputFolder.exists == false) outputFolder.create();

        var suffix = prompt('Enter the suffix to append:', '');
        if (suffix == null) { return }; // Test if cancel returns null, then do nothing.  
        if (suffix == "") { return }; // Test if an empty string is returned, then do nothing.
        /* https://prepression.blogspot.com/2019/03/bridge-batch-rename-to-clean-invalid.html */
        var suffixCleansed = suffix.replace(/[^-_0-9a-zA-Z]/gi, '');

        var inputFiles = inputFolder.getFiles(/\.(jpg|jpeg|tif|tiff|psd|psb|eps|png|bmp|gif)$/i); // Add or remove as required

        app.displayDialogs = DialogModes.NO;

        for (var a = 0; a < inputFiles.length; a++) {
            try {
                var inDoc = open(inputFiles[a]);

                // START DOING STUFF

                    /* CONDITION #1 */
                if (app.activeDocument.name.indexOf('-RED') != -1) {
                    app.doAction('Red Action', 'Change Colour Action Set'); // Change action & action set name
                    /* CONDITION #1 */

                    /* CONDITION #2 */
                } else if (app.activeDocument.name.indexOf('-GREEN') != -1) {
                    app.doAction('Green Action', 'Change Colour Action Set'); // Change action & action set name
                    /* CONDITION #2 */

                    /* CONDITION #3 */
                } else if (app.activeDocument.name.indexOf('-BLUE') != -1) {
                    app.doAction('Blue Action', 'Change Colour Action Set'); // Change action & action set name
                    /* CONDITION #3 */

                } else {
                    /* DO SOMETHING ELSE */
                }

                var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
                var saveFileJPEG = new File(outputFolder + '/' + docName + '_' + suffixCleansed + '.jpg');
                SaveForWeb(saveFileJPEG);

                app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

                // FINISH DOING STUFF

                // JPEG S4W Options
                function SaveForWeb(saveFileJPEG, jpegQuality) {
                    /*
                    // Convert to sRGB Step
                        if (app.activeDocument.colorProfileName.substring(0, 4) != "sRGB")
                        app.activeDocument.convertProfile("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, false); // BPC, Dither
                    */
                    var sfwOptions = new ExportOptionsSaveForWeb();
                    sfwOptions.format = SaveDocumentType.JPEG;
                    sfwOptions.includeProfile = true;
                    sfwOptions.optimized = true;
                    sfwOptions.quality = 70;
                    activeDocument.exportDocument(saveFileJPEG, ExportType.SAVEFORWEB, sfwOptions);
                }

            } catch (e) {
                continue;
            }
        }

        app.displayDialogs = savedDisplayDialogs;
        alert('Script completed!' + '\n' + inputFiles.length + ' files saved to:' + '\n' + outputFolder.fsName);

    } else {
        alert('Please close all open files before running this script');
    }
}
)();

 

 

Likes

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