script for phone case mockup

Community Beginner ,
Sep 28, 2019 Sep 28, 2019

Copy link to clipboard

Copied

can someone help me how to replace image on mockup with auto action or script and save it as jpeg ?

i try action but keep fail and dont know wahts wrong with my action script

i still new on photoshop and sry for my bad english

this is my mockup and photo exampleCapture.JPG

TOPICS
Actions and scripting

Views

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

Community Expert , Sep 28, 2019 Sep 28, 2019

Here is a script that will replace the selected Smart Object layer with a file from a source folder, then save the file as a jpg to an output folder. It will loop through the source folder and replace the original smart object with each file in the source folder, All the source files have to be the same size! In the script, I have the source folder being on the desktop and called "source files." The output folder is a subfolder, in source files, called "done." You can change the code to reflect

...

Likes

Translate

Translate
Community Expert ,
Sep 28, 2019 Sep 28, 2019

Copy link to clipboard

Copied

Here is a script that will replace the selected Smart Object layer with a file from a source folder, then save the file as a jpg to an output folder. It will loop through the source folder and replace the original smart object with each file in the source folder, All the source files have to be the same size! In the script, I have the source folder being on the desktop and called "source files." The output folder is a subfolder, in source files, called "done." You can change the code to reflect whatever folders you want to use. I also added a "-Flat" suffix to the saved jpg files to avoid overwriting anything.

 

var srcFolder = new Folder('~/desktop/source files/');
var outputFolder = new Folder('~/desktop/source files/done/');

var searchMask = '*.???'
var fileList = srcFolder.getFiles(searchMask);

var doc = activeDocument;
var curLayer = doc.activeLayer;
var soName
var jpgOptions = new JPEGSaveOptions();
jpgOptions.quality = 8;

for (var i=0;i<fileList.length;i++){
    replaceSO (fileList[i]);
    var fName = fileList[i].name.split('.')[0];
    dupeFile ();
    var doc2 = activeDocument;
    doc2.saveAs(new File(outputFolder +'/'+fName + '-flat.jpg'),jpgOptions);
    doc2.close(SaveOptions.DONOTSAVECHANGES);
    }

function replaceSO(file){
    var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );
        var desc5 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
        desc5.putPath( idnull, new File( file ) );
    executeAction( idplacedLayerReplaceContents, desc5, DialogModes.NO );
    }

function dupeFile(){
    var idDplc = charIDToTypeID( "Dplc" );
        var desc11 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref1 = new ActionReference();
            var idDcmn = charIDToTypeID( "Dcmn" );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idFrst = charIDToTypeID( "Frst" );
            ref1.putEnumerated( idDcmn, idOrdn, idFrst );
        desc11.putReference( idnull, ref1 );
        var idMrgd = charIDToTypeID( "Mrgd" );
        desc11.putBoolean( idMrgd, true );
    executeAction( idDplc, desc11, DialogModes.NO );    
    }

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
Community Beginner ,
Sep 28, 2019 Sep 28, 2019

Copy link to clipboard

Copied

Waw thank u so much for your help. Can i ask u another question ? Did i must copy that script on notepad and save them as jsx ?

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
New Here ,
Nov 25, 2019 Nov 25, 2019

Copy link to clipboard

Copied

Hello Chuck, i wanna ask that I used your script on Photoshop CS6 but it shows error 8800; General Photoshop error occurred. This functionality may not be available in this version of Photoshop.

- The command "Replace Contents" is not currently available.

Line: 27

->  executeAction( idplacedLayerReplaceContents, desc5, DialogModes.NO );

 

Do you know how to fix it?

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
New Here ,
Nov 25, 2019 Nov 25, 2019

Copy link to clipboard

Copied

Oops, nevermind I solved it.

I forgot to resize the images to be the same size.

Thanks for the script tho, it helps many people!

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

Copy link to clipboard

Copied

Hi Chuck,

 

Thank you its working fine with source folder but jpeg is not getting saved automatically in done folder even though i created the folder in same loaction as you mentioned.

Secondly everytime its asking to save manually and names of JPEGs are also not chaging so its asking to replace or rename.

Please confirm what should I do in that case

 

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
New Here ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Hi Ankit,
I have the same issue with automatic saving of jpegs, did you find a solution ?
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
New Here ,
Apr 04, 2021 Apr 04, 2021

Copy link to clipboard

Copied

Hello Chuck,

 

First of all, thank you very much for sharing the solution here. I have also applied the above code and it works. I need support in one matter. It runs the Save As method each time while saving the processed images. Instead, what kind of editing should be done in the code to give it the name of the rendered image directly and save it in 12 quality?

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 ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

This is a great script and very similar to the answer I am looking for, in my case, is not just one mockup in the PSD file, is do all this but multiple times, I mean the same file from the folder will replace the content in the smart object (and in around 9 more smart object copies over a different "background no background" layer that is under the every smart object copy, ) then what I need to do is to save those 10 mockups for each image (because the different background), so If I explain my self well, I need 10 different JPGS for each file in the folder, Did I was able to explain myself?

 

thank you for any light you can bring to this , blessings.

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
Community Expert ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

@AlexPrint So you just have one common smart object with several other smartobjects that are "linked" to that one smart object? An you want several files saved with each of those smart objects and a different background or multiple backgrounds? Is your working file always the same structure: same number of layers, in the same order, with the same names? Are there more layers than just the smart object and the background layer that you want saved to each file? Can you post an example of your layer structure?

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
New Here ,
Jul 03, 2022 Jul 03, 2022

Copy link to clipboard

Copied

Hi Chuck, 

This solution worked beautifully for me this morning, and is the BEST version of this script I've found on these forums, Thank you SO much!! But for some reason - a few hours later -  it's stopped working 😢 

Photoshop seems to be saving the files as PSDs rather than JPGs and stopping on a "save as" screen, where I have to hit "save" for it to continue. 

Not sure why this has happened when I didn't change anything about the files / scripts / process.
Wondering if it has to do with the latest version of Photoshop, and the 'save to cloud' screen that sometimes comes up, even tho i've turned it off 🤔 
Any ideas?

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
Community Expert ,
Jul 03, 2022 Jul 03, 2022

Copy link to clipboard

Copied

Did you update PS? My guess is that the preferences got changed to the now default of not allowing layered files to be saved as jpgs. Check the preferences and make sure the file saving is set to Legacy.

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
New Here ,
Jul 04, 2022 Jul 04, 2022

Copy link to clipboard

Copied

thanks chuck! I figured out what it was.

I had to have a locked background layer in the file, otherwise it doesn't work

Multiple layers is fine, as long as there is a locked BG layer

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
Community Expert ,
Jul 04, 2022 Jul 04, 2022

Copy link to clipboard

Copied

LATEST

Very good. Glad you got it figured out.

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
Community Expert ,
Sep 28, 2019 Sep 28, 2019

Copy link to clipboard

Copied

Yes, save as plain text with an extension of .jsx.

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
Community Beginner ,
Sep 28, 2019 Sep 28, 2019

Copy link to clipboard

Copied

I already save it as jsx. So what i must do to run the 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
Community Expert ,
Sep 28, 2019 Sep 28, 2019

Copy link to clipboard

Copied

To run the script, put in Photoshop's subfolder: Presets/Scripts, then restart Photoshop. Go to File>Scripts in the main menu, and you should see your script listed. If not, use the browse butto . To navigate to it to run it. Just make sure you have your source and output folders setup as I mentioned in my previous post, or change the paths in the code to where you have those folders.

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
Community Beginner ,
Sep 28, 2019 Sep 28, 2019

Copy link to clipboard

Copied

Ohh iget it. So i just need chanve source code and done to my file name right ? After that i just need go to file>script and click on my scriot

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
Community Expert ,
Sep 28, 2019 Sep 28, 2019

Copy link to clipboard

Copied

Yes, but the script I wrote works on a folder of files, so you have to make sure the path is for the folder, and not just one file. If you only have one file that you want to replace in your smart object, then just put that one in the source folder.

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
Community Beginner ,
Sep 28, 2019 Sep 28, 2019

Copy link to clipboard

Copied

i have folder with 500 image called GUNDAM and after that i save it to folder called MOCKUP

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
Community Beginner ,
Sep 28, 2019 Sep 28, 2019

Copy link to clipboard

Copied

i havar srcFolder = new Folder('~/desktop/GUNDAM/'); var outputFolder = new Folder('~/desktop/source files/MOCKUP/'); i must change like this 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
Community Expert ,
Sep 28, 2019 Sep 28, 2019

Copy link to clipboard

Copied

The folder GUNDAM, as you have it should be right on your desktop. You can just have the folder MOCKUP directly on your desktop also, by deleting the "/source files" part of the code.

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
Community Expert ,
Sep 28, 2019 Sep 28, 2019

Copy link to clipboard

Copied

Okay, so you need to change the two folder paths in my script to where you actually have the folders.

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
Community Beginner ,
Sep 28, 2019 Sep 28, 2019

Copy link to clipboard

Copied

var srcFolder = new Folder('~/desktop/GUNDAM/'); var outputFolder = new Folder('~/desktop/source files/MOCKUP/');

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
Community Expert ,
Sep 28, 2019 Sep 28, 2019

Copy link to clipboard

Copied

With ('~/desktop/source files/MOCKUP/', you need to that the folder MOCKUP inside another folder called source files.

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