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, How to, Problem or error

Views

2.1K

Likes

translate

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 , 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

Translate
Adobe Community Professional ,
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

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

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

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

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

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

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

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

Copy link to clipboard

Copied

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

Likes

translate

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

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 ,
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

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

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 ,
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

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

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

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 ,
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

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 ,
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

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

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 ,
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

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

Hey buddy its work. Thx for teaching me amd answer all of my question. Not every people want to share they knowledge for free

Likes

translate

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 ,
Sep 29, 2019 Sep 29, 2019

Copy link to clipboard

Copied

Very good!

Likes

translate

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 ,
Dec 03, 2019 Dec 03, 2019

Copy link to clipboard

Copied

hey chuck i need your help, i try ue your script and this eror popout. I dont know how to fix it. already try any method but stil no work

 

Untitled.jpg

Likes

translate

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 ,
Dec 03, 2019 Dec 03, 2019

Copy link to clipboard

Copied

DOD you try my suggestions on you other post regarding the names of the files? That first file in you screen shot has all that garbage lettering after it.

Likes

translate

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 ,
Dec 03, 2019 Dec 03, 2019

Copy link to clipboard

Copied

already change the name to 1 letter but still not work

Likes

translate

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 ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

sardonicHumour();

function sardonicHumour() {
    alert("Thx for giving away free iPhone cases. Not every people want to share they product for free");
}

Likes

translate

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