Highlighted

Batch replace smart objects

Community Beginner ,
Jan 30, 2014

Copy link to clipboard

Copied

Hello,

I have very minimal scripting knowledge, and every script I've found for this workflow is partial or results in "undefined".  I am on a mac running Photoshop CC (latest update).

This is what I have:

  • a mockup file of a book with the cover image set as a transformed smart object
  • a folder of images resized to fit said smart object

This is what I would like a script to do (if possible):

  • for every image in said folder
  • replace smart object with images
  • save each new mockup (one for each new image) as a PSD file.

We have to create over 40 book, CD, DVD, and Blu-Ray mockups for each flyer we do.  Smart Objects help streamline it a little but I'm just going through and using an action right now, which I know is less than ideal.  I don't mind if the file names aren't what I need them to be, so incremental file naming would be fine because I could rename them all later.

Any suggestions on how I could streamline this process without having to manually replace and save?

Please try this:

// replace smart object’s content and save psd;

// 2011, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

var thePath = myDocument.path;

var theLayer = myDocument.activeLayer;

// psd options;

psdOpts = new PhotoshopSaveOptions();

psdOpts.embedColorProfile = true;

psdOpts.alphaChannels = true;

psdOpts.layers = true;

psdOpts.spotColors = true;

// check if layer is smart object;

if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}

else {

// select files;

if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.psd;*.tif", true)}

else {var theFiles = File.openDialog ("please select files", getFiles, true)};

if (theFiles) {

// work through the array;

          for (var m = 0; m < theFiles.length; m++) {

// replace smart object;

                    theLayer = replaceContents (theFiles, theLayer);

                    var theNewName = theFiles.name.match(/(.*)\.[^\.]+$/)[1];

//Raise color picker for Back cover;

try {

app.activeDocument.activeLayer = app.activeDocument.layers[app.activeDocument.layers.length - 1];

// =======================================================

var idsetd = charIDToTypeID( "setd" );

var desc7 = new ActionDescriptor();

var idnull = charIDToTypeID( "null" );

var ref2 = new ActionReference();

var idcontentLayer = stringIDToTypeID( "contentLayer" );

var idOrdn = charIDToTypeID( "Ordn" );

var idTrgt = charIDToTypeID( "Trgt" );

ref2.putEnumerated( idcontentLayer, idOrdn, idTrgt );

desc7.putReference( idnull, ref2 );

var idT = charIDToTypeID( "T   " );

var desc8 = new ActionDescriptor();

var idClr = charIDToTypeID( "Clr " );

var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );

desc7.putObject( idT, idsolidColorLayer, desc8 );

executeAction( idsetd, desc7, DialogModes.ALL );

} catch (e) {};

//save jpg;

                    myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".psd")),psdOpts,true);

                    }

          }

}

};

////// get psds, tifs and jpgs from files //////

function getFiles (theFile) {

     if (theFile.name.match(/\.(psd|tif)$/i) != null || theFile.constructor.name == "Folder") {

          return true

          };

     };

////// replace contents //////

function replaceContents (newFile, theSO) {

app.activeDocument.activeLayer = theSO;

// =======================================================

var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );

    var desc3 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc3.putPath( idnull, new File( newFile ) );

    var idPgNm = charIDToTypeID( "PgNm" );

    desc3.putInteger( idPgNm, 1 );

executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );

return app.activeDocument.activeLayer

};

Topics

Actions and scripting

Views

19.5K

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

Batch replace smart objects

Community Beginner ,
Jan 30, 2014

Copy link to clipboard

Copied

Hello,

I have very minimal scripting knowledge, and every script I've found for this workflow is partial or results in "undefined".  I am on a mac running Photoshop CC (latest update).

This is what I have:

  • a mockup file of a book with the cover image set as a transformed smart object
  • a folder of images resized to fit said smart object

This is what I would like a script to do (if possible):

  • for every image in said folder
  • replace smart object with images
  • save each new mockup (one for each new image) as a PSD file.

We have to create over 40 book, CD, DVD, and Blu-Ray mockups for each flyer we do.  Smart Objects help streamline it a little but I'm just going through and using an action right now, which I know is less than ideal.  I don't mind if the file names aren't what I need them to be, so incremental file naming would be fine because I could rename them all later.

Any suggestions on how I could streamline this process without having to manually replace and save?

Please try this:

// replace smart object’s content and save psd;

// 2011, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

var thePath = myDocument.path;

var theLayer = myDocument.activeLayer;

// psd options;

psdOpts = new PhotoshopSaveOptions();

psdOpts.embedColorProfile = true;

psdOpts.alphaChannels = true;

psdOpts.layers = true;

psdOpts.spotColors = true;

// check if layer is smart object;

if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}

else {

// select files;

if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.psd;*.tif", true)}

else {var theFiles = File.openDialog ("please select files", getFiles, true)};

if (theFiles) {

// work through the array;

          for (var m = 0; m < theFiles.length; m++) {

// replace smart object;

                    theLayer = replaceContents (theFiles, theLayer);

                    var theNewName = theFiles.name.match(/(.*)\.[^\.]+$/)[1];

//Raise color picker for Back cover;

try {

app.activeDocument.activeLayer = app.activeDocument.layers[app.activeDocument.layers.length - 1];

// =======================================================

var idsetd = charIDToTypeID( "setd" );

var desc7 = new ActionDescriptor();

var idnull = charIDToTypeID( "null" );

var ref2 = new ActionReference();

var idcontentLayer = stringIDToTypeID( "contentLayer" );

var idOrdn = charIDToTypeID( "Ordn" );

var idTrgt = charIDToTypeID( "Trgt" );

ref2.putEnumerated( idcontentLayer, idOrdn, idTrgt );

desc7.putReference( idnull, ref2 );

var idT = charIDToTypeID( "T   " );

var desc8 = new ActionDescriptor();

var idClr = charIDToTypeID( "Clr " );

var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );

desc7.putObject( idT, idsolidColorLayer, desc8 );

executeAction( idsetd, desc7, DialogModes.ALL );

} catch (e) {};

//save jpg;

                    myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".psd")),psdOpts,true);

                    }

          }

}

};

////// get psds, tifs and jpgs from files //////

function getFiles (theFile) {

     if (theFile.name.match(/\.(psd|tif)$/i) != null || theFile.constructor.name == "Folder") {

          return true

          };

     };

////// replace contents //////

function replaceContents (newFile, theSO) {

app.activeDocument.activeLayer = theSO;

// =======================================================

var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );

    var desc3 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc3.putPath( idnull, new File( newFile ) );

    var idPgNm = charIDToTypeID( "PgNm" );

    desc3.putInteger( idPgNm, 1 );

executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );

return app.activeDocument.activeLayer

};

Topics

Actions and scripting

Views

19.5K

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
LEGEND ,
Jan 31, 2014

Copy link to clipboard

Copied

Have you found a Scripting solution yet?

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
Reply
Loading...
Community Beginner ,
Jan 31, 2014

Copy link to clipboard

Copied

Yes - sort of - thank you!  My ultimate goal in all this is automating each type of mockup we need to create (CD, DVD, Blu-Ray, Book, all different facings, etc).

I am using a script (that I believe you wrote) but I can only use it for certain circumstances (and for paperback right facing books only) because sometimes I would need to create the spine of the DVD, book, or side panel of the CD, which would involve more than one smart object and creating those elements would take just as much work on my end creating the folder of files than scripting would help.  I replaced what you suggested in the other thread and it works now with selecting items in a folder.

For a hardcover book facing right, There is only ONE more step I would need to add to the script to make this type of mockup fully automated and that is to have the option to change the color of the little bit of back cover that's showing (the highlighted layer in the example below) Which would involve just a dialog to modify that one layer.  I would need to be to select the new color (to match the cover, obviously), and then the script can continue on with saving the new PSD as normal.

Screen Shot 2014-01-31 at 9.25.48 AM.jpg

Any suggestions on how i can add to this script to be able to change that layer?  I don't want to get too complicated with all of this, but we do this EVERY MONTH so it would be of great use to us.

Thanks in advance for sharing your knowledge with the Adobe community!

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
Reply
Loading...
LEGEND ,
Jan 31, 2014

Copy link to clipboard

Copied

What are the unmistakeable characteristics of that Layer?

It seems to share its name with another one, but is it always the lowermost Layer?

Or at least the lowermost Solid Color 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
Reply
Loading...
Community Beginner ,
Jan 31, 2014

Copy link to clipboard

Copied

It is always the lowermost layer and always a solid color.

Here are it's properties:

Screen Shot 2014-01-31 at 9.36.53 AM.jpg

Thank you for your time 🙂

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
Reply
Loading...
LEGEND ,
Jan 31, 2014

Copy link to clipboard

Copied

I am using a script (that I believe you wrote) but I can only use it for certain circumstances (and for paperback right facing books only) because sometimes I would need to create the spine of the DVD, book, or side panel of the CD, which would involve more than one smart object and creating those elements would take just as much work on my end creating the folder of files than scripting would help.

There are some options for this, I guess.

Proper 3D would be one – but I’m not sure how well that scripts.

If you have the full dustcover (including back and spine) one could employ two clipped SOs – one for the cover and one for the spine and place the full object in those.

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
Reply
Loading...
LEGEND ,
Jan 31, 2014

Copy link to clipboard

Copied

This is pretty crude but it might work for raising the Sold Color dialog for the lowermost layer.

try {

app.activeDocument.activeLayer = app.activeDocument.layers[app.activeDocument.layers.length - 1];

//

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var layerDesc = executeActionGet(ref);

var adjList = layerDesc.getList(stringIDToTypeID('adjustment'));

var theColors = adjList.getObjectValue(0).getObjectValue(stringIDToTypeID('color'));

var theRed = theColors.getUnitDoubleValue(theColors.getKey(0));

var theGreen = theColors.getUnitDoubleValue(theColors.getKey(1));

var theBlue = theColors.getUnitDoubleValue(theColors.getKey(2));

// =======================================================

var idsetd = charIDToTypeID( "setd" );

    var desc7 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref2 = new ActionReference();

        var idcontentLayer = stringIDToTypeID( "contentLayer" );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idTrgt = charIDToTypeID( "Trgt" );

        ref2.putEnumerated( idcontentLayer, idOrdn, idTrgt );

    desc7.putReference( idnull, ref2 );

    var idT = charIDToTypeID( "T   " );

        var desc8 = new ActionDescriptor();

        var idClr = charIDToTypeID( "Clr " );

    var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );

    desc7.putObject( idT, idsolidColorLayer, desc8 );

executeAction( idsetd, desc7, DialogModes.ALL );

} catch (e) {};

Have a good weekend!

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
Reply
Loading...
Community Beginner ,
Jan 31, 2014

Copy link to clipboard

Copied

Where do I paste the above in the existing script? and do I have to change the names of anything to match the name of my layer?  Here's what I'm using:

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

var thePath = myDocument.path;

var theLayer = myDocument.activeLayer;

// psd options;

psdOpts = new PhotoshopSaveOptions();

psdOpts.embedColorProfile = true;

psdOpts.alphaChannels = true;

psdOpts.layers = true;

psdOpts.spotColors = true;

// check if layer is smart object;

if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}

else {

// select files;

if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.png;*.jpg;*.psd;*.tif", true)}

else {var theFiles = File.openDialog ("please select files", getFiles, true)};

if (theFiles) {

// work through the array;

          for (var m = 0; m < theFiles.length; m++) {

// replace smart object;

                    theLayer = replaceContents (theFiles);

                    var theNewName = theFiles.name.match(/(.*)\.[^\.]+$/)[1];

//save PSD;

                    myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".psd")),psdOpts,true);

                    }

          }

}

};

////// get psds, tifs and jpgs from files //////

function getFiles (theFile) {

     if (theFile.name.match(/\.(psd|tif|jpg)$/i) != null || theFile.constructor.name == "Folder") {

          return true

          };

     };

////// replace contents //////

function replaceContents (newFile) {

// =======================================================

var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );

    var desc3 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc3.putPath( idnull, new File( newFile ) );

    var idPgNm = charIDToTypeID( "PgNm" );

    desc3.putInteger( idPgNm, 1 );

executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );

return app.activeDocument.activeLayer

};

Sorry for the basic questions..

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
Reply
Loading...
LEGEND ,
Feb 02, 2014

Copy link to clipboard

Copied

Where do I paste the above in the existing script?

Inserting it before the line

//save PSD;

should raise the Color Picker window before saving the new file/s.

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
Reply
Loading...
Community Beginner ,
Feb 03, 2014

Copy link to clipboard

Copied

I tried pasting it there and it stops after it replaces the smart object and does not even go on to the saving, unfortunately.  Here's the script below:

/ replace smart object’s content and save psd;

// 2011, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

var thePath = myDocument.path;

var theLayer = myDocument.activeLayer;

// psd options;

psdOpts = new PhotoshopSaveOptions();

psdOpts.embedColorProfile = true;

psdOpts.alphaChannels = true;

psdOpts.layers = true;

psdOpts.spotColors = true;

// check if layer is smart object;

if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}

else {

   

// select files;

if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.png;*.jpg;*.psd;*.tif", true)}

else {var theFiles = File.openDialog ("please select files", getFiles, true)};

if (theFiles) {

   

// work through the array;

          for (var m = 0; m < theFiles.length; m++) {

             

// replace smart object;

                    theLayer = replaceContents (theFiles);

                    var theNewName = theFiles.name.match(/(.*)\.[^\.]+$/)[1];

                   

//Raise color picker for Back cover                   

                        try {

    app.activeDocument.activeLayer = app.activeDocument.layers[app.activeDocument.layers.length - 1];

    //

    var ref = new ActionReference();

    ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

    var layerDesc = executeActionGet(ref);

    var adjList = layerDesc.getList(stringIDToTypeID('adjustment'));

    var theColors = adjList.getObjectValue(0).getObjectValue(stringIDToTypeID('color'));

    var theRed = theColors.getUnitDoubleValue(theColors.getKey(0));

    var theGreen = theColors.getUnitDoubleValue(theColors.getKey(1));

    var theBlue = theColors.getUnitDoubleValue(theColors.getKey(2));

    // =======================================================

    var idsetd = charIDToTypeID( "setd" );

        var desc7 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref2 = new ActionReference();

            var idcontentLayer = stringIDToTypeID( "contentLayer" );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref2.putEnumerated( idcontentLayer, idOrdn, idTrgt );

        desc7.putReference( idnull, ref2 );

        var idT = charIDToTypeID( "T   " );

            var desc8 = new ActionDescriptor();

            var idClr = charIDToTypeID( "Clr " );

        var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );

        desc7.putObject( idT, idsolidColorLayer, desc8 );

    executeAction( idsetd, desc7, DialogModes.ALL );

    } catch (e) {};

//save PSD;

                    myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".psd")),psdOpts,true);

                    }

          }

}

};

////// get psds, tifs and jpgs from files //////

function getFiles (theFile) {

     if (theFile.name.match(/\.(psd|tif|jpg)$/i) != null || theFile.constructor.name == "Folder") {

          return true

          };

     };

////// replace contents //////

function replaceContents (newFile) {

// =======================================================

var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );

    var desc3 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc3.putPath( idnull, new File( newFile ) );

    var idPgNm = charIDToTypeID( "PgNm" );

    desc3.putInteger( idPgNm, 1 );

executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );

return app.activeDocument.activeLayer

};

Sorry, I wish I was a scripter so I could troubleshoot myself!  I am in the process of teaching myself, however.

Thanks for your time!

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
Reply
Loading...
Community Beginner ,
Feb 03, 2014

Copy link to clipboard

Copied

actually it saved it, but just didn't raise the color picker.

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
Reply
Loading...
LEGEND ,
Feb 04, 2014

Copy link to clipboard

Copied

Please try this:

// replace smart object’s content and save psd;

// 2011, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

var thePath = myDocument.path;

var theLayer = myDocument.activeLayer;

// psd options;

psdOpts = new PhotoshopSaveOptions();

psdOpts.embedColorProfile = true;

psdOpts.alphaChannels = true;

psdOpts.layers = true;

psdOpts.spotColors = true;

// check if layer is smart object;

if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}

else {

// select files;

if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.psd;*.tif", true)}

else {var theFiles = File.openDialog ("please select files", getFiles, true)};

if (theFiles) {

// work through the array;

          for (var m = 0; m < theFiles.length; m++) {

// replace smart object;

                    theLayer = replaceContents (theFiles, theLayer);

                    var theNewName = theFiles.name.match(/(.*)\.[^\.]+$/)[1];

//Raise color picker for Back cover;

try {

app.activeDocument.activeLayer = app.activeDocument.layers[app.activeDocument.layers.length - 1];

// =======================================================

var idsetd = charIDToTypeID( "setd" );

var desc7 = new ActionDescriptor();

var idnull = charIDToTypeID( "null" );

var ref2 = new ActionReference();

var idcontentLayer = stringIDToTypeID( "contentLayer" );

var idOrdn = charIDToTypeID( "Ordn" );

var idTrgt = charIDToTypeID( "Trgt" );

ref2.putEnumerated( idcontentLayer, idOrdn, idTrgt );

desc7.putReference( idnull, ref2 );

var idT = charIDToTypeID( "T   " );

var desc8 = new ActionDescriptor();

var idClr = charIDToTypeID( "Clr " );

var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );

desc7.putObject( idT, idsolidColorLayer, desc8 );

executeAction( idsetd, desc7, DialogModes.ALL );

} catch (e) {};

//save jpg;

                    myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".psd")),psdOpts,true);

                    }

          }

}

};

////// get psds, tifs and jpgs from files //////

function getFiles (theFile) {

     if (theFile.name.match(/\.(psd|tif)$/i) != null || theFile.constructor.name == "Folder") {

          return true

          };

     };

////// replace contents //////

function replaceContents (newFile, theSO) {

app.activeDocument.activeLayer = theSO;

// =======================================================

var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );

    var desc3 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc3.putPath( idnull, new File( newFile ) );

    var idPgNm = charIDToTypeID( "PgNm" );

    desc3.putInteger( idPgNm, 1 );

executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );

return app.activeDocument.activeLayer

};

Likes

1 Like

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
Reply
Loading...
Community Beginner ,
Feb 05, 2014

Copy link to clipboard

Copied

This worked after I ungrouped the layers.  Thank you so much for all your help, it is really appreciated!

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
Reply
Loading...
Community Beginner ,
Feb 24, 2014

Copy link to clipboard

Copied

Hi, thank you for your solution provided here.  I tried to use the script and it takes me to the "Choose files" folder and I can't choose anything.  This is what I did.

I copied the scirpt into a text doc and named it ending with .js

I go to File > Scripts > Browse and select the script.

It first gave me an error that I wasn't selecting layer with the smart object so I choose the layer with the smart object.

After that it let me get to the "Choose files" but won't let me actually select the folder.

Here's what I need to accompliish.

I have a psd with a smart layer in 4 different layers.  I want to replace the image in that smart layer so it will replace the instances in all 4 layers.  I have 500 different images I need done so I'd like to be able to batch switch them.

Can you help?

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
Reply
Loading...
LEGEND ,
Feb 26, 2014

Copy link to clipboard

Copied

Do you work on Mac or Windows?

Did you use the Script from post 14?

After that it let me get to the "Choose files" but won't let me actually select the folder.

It won’t let you select a Folder but Files.

The try-clause after

//Raise color picker for Back cover;

probably makes no sense for you.

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
Reply
Loading...
New Here ,
Mar 21, 2014

Copy link to clipboard

Copied

I have an identical requirement as www.impactcolorprint.com.

Could a folder be selected instead of individual files (selecting several hundred would be difficult)?

If our starting PSD has multiple layers of the same smart object, replacing the contents of that smart object would update them all, correct?

Lastly, I would like to see the updated PSD file saved as jpg with the originating file name from the folder we selected.

template.psd (containing smart object)

Chose...

Images_Folder >
image_1.jpg

image_2.jpg

image_3.jpg

......

template.psd (with updated smart object visisilbe on all layers)

Ouput:

Output_Folder >

image_1.jpg

image_2.jpg

image_3.jpg

....

I still have trouble with some of the javascript syntax so any assistance would be greatly appreciated.

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
Reply
Loading...
LEGEND ,
Mar 21, 2014

Copy link to clipboard

Copied

When replacing a Smart Object all its instances should update indeed.

Selecting a Folder instead of Files can be done by changing the corresponding lines to

var theFolder = Folder.selectDialog ("select folder");

if (theFolder) {

var theFiles = theFolder.getFiles(/\.(jpg|tif|eps|psd)$/i)

};

Saving jpgs can be done directly or with a function like this:

function SaveJPG(saveFile, jpegQuality){

jpgSaveOptions = new JPEGSaveOptions();

jpgSaveOptions.embedColorProfile = true;

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

jpgSaveOptions.matte = MatteType.NONE;

jpgSaveOptions.quality = jpegQuality; //1-12

activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);

}

but you need to use the correct path as the »saveFile«-argument.

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
Reply
Loading...
New Here ,
Mar 22, 2014

Copy link to clipboard

Copied

Thanks for the great feedback. I have it working beautifully.

One last question...

My images vary in width and height. I would like them to be maintain their aspect ratio, while fitting the shortest side (width or height) of the smart object it is replacing (which is a square).

Ideally I'd like the new images to have white space on top and bottom or the sides but not exceed the bounds of the original smart object in the template.

Is this possible? I'm assuming any manipulation would be done right after the "executeAction(idplacedLayerReplaceContents... " command.

Is there a way to do this?

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
Reply
Loading...
Most Valuable Participant ,
Mar 22, 2014

Copy link to clipboard

Copied

luis_mendes wrote:

My images vary in width and height. I would like them to be maintain their aspect ratio, while fitting the shortest side (width or height) of the smart object it is replacing (which is a square).

I think there is a basic problem here with your understanding of how smart object layers work.

The layer embedded object what ever it may be.  Has pixels  rendered for it for the smart objects layers content and there is and associated transform for the layer.   These pixels are protected from change you can not directly alter them.  When you change the layer size you do it by altering the layers transform.  You can also attach smart filters to the layers content and mask the layer. You can not use tool on the layers that alter pixels no paint, erase,  lines etc.  If you use layer duplicate to dupe the layer the dup layer shares the embedded object.  You can transform  layers that share an embedded object to form a picture package the changing each layers associated transform. To different areas over the documents canvas.  When you replace the shared embedded smart object all the layers that share the object change.  The associated transforms are not changed. If you do not replace the current embedded object with an object that is the same size the smart object layers associated transforms will not work the way you would expect then to work. For the were set for a different size object.

If you know the output area size and its location you should be able to script what you want. I would think after you replace the embedded content. You could set the layers transform to 100% width and 100% height get the layers bounds and calculate the required transform. for the output area. I do something like that in my collage package.  However I resize the image to fill the output area and mask off any excess image so the image get aspect ratio of the output area and looks like a centered crop.

However from the example template in this thread there look to be a perspective transform involved which may have some rotation. I have never tried to program in the ability to handle rotation and prospective placement of images.   I just tweak the populated collage manually if an image or two need that type of transform.

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
Reply
Loading...
LEGEND ,
Mar 23, 2014

Copy link to clipboard

Copied

Could you please post examples of the image with the original SO and examples for portrait and landscape replacement images as you want them to look? 

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
Reply
Loading...
New Here ,
Mar 23, 2014

Copy link to clipboard

Copied

I have managed to solve for this by evaluating each smart object after it is replaced and scaling it in the parent PSD. Works perfectly)! Thanks again for the feedback.

What I had hoped for was the ability to manipulate the new smart object contents to fit the starting size of the initial, embedded smart object.

Here's an example PSD file — On it, multiple layers of the same smart object (in green).

The smart object is originally 200 x 200 px.

depositphotos_10254962-Leaflet-notebook-textbook-white-blank-paper-template.jpg

Now, using a folder of images, I swap out the contents of the green smart object.

american-clothing-logos-74108.jpg

The logos vary in width, height, and pixel size - so when the script is run they can sometimes exceed the bounds of the green boxes in the native document.

Again, I have solved for this by evaluating each layer after the SO has been updated with each logo, and back in the parent PSD.

But, what I was most curious about was if it was possible to do this during the manipulation of the smart object and immediately after/during "executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );" Thus placing a logo which is already "fitted" to the green area, without stretching the logo (beyond the transform of the parent PSD).

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
Reply
Loading...
LEGEND ,
Mar 23, 2014

Copy link to clipboard

Copied

I would recommend a different approach:

Open the SO, place and if necessary scale the replacement files there, hide the background and save/close the SO.

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
Reply
Loading...
New Here ,
Mar 23, 2014

Copy link to clipboard

Copied

That was my initial though. But can that be done? How? I havent been able to target the SO after it is replaced.

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
Reply
Loading...
LEGEND ,
Mar 23, 2014

Copy link to clipboard

Copied

You’d have to foregoe the replacing and instead open the SO, then place the file.

Something like this – if you have the Preference set to scale placed SOs (»Resize Image During Place«) this might suffice, otherwise you may have to scale the newly placed SO in the SO.

////// open smart object //////

function placeSmartObjectInSmartObject (theLayer, thisFile) {

if (theLayer.kind == "LayerKind.SMARTOBJECT") {

// =======================================================

var idplacedLayerEditContents = stringIDToTypeID( "placedLayerEditContents" );

    var desc2 = new ActionDescriptor();

executeAction( idplacedLayerEditContents, desc2, DialogModes.NO );

// place so;

// =======================================================

var idPlc = charIDToTypeID( "Plc " );

    var desc4 = new ActionDescriptor();

    var idAs = charIDToTypeID( "As  " );

        var desc5 = new ActionDescriptor();

        var idfsel = charIDToTypeID( "fsel" );

        var idpdfSelection = stringIDToTypeID( "pdfSelection" );

        var idpage = stringIDToTypeID( "page" );

        desc5.putEnumerated( idfsel, idpdfSelection, idpage );

        var idPgNm = charIDToTypeID( "PgNm" );

        desc5.putInteger( idPgNm, 1 );

        var idCrop = charIDToTypeID( "Crop" );

        var idcropTo = stringIDToTypeID( "cropTo" );

        var idtrimBox = stringIDToTypeID( "trimBox" );

        desc5.putEnumerated( idCrop, idcropTo, idtrimBox );

    var idPDFG = charIDToTypeID( "PDFG" );

    desc4.putObject( idAs, idPDFG, desc5 );

    var idnull = charIDToTypeID( "null" );

    desc4.putPath( idnull, new File( thisFile ) );

    var idFTcs = charIDToTypeID( "FTcs" );

    var idQCSt = charIDToTypeID( "QCSt" );

    var idQcsa = charIDToTypeID( "Qcsa" );

    desc4.putEnumerated( idFTcs, idQCSt, idQcsa );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc6 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idRlt = charIDToTypeID( "#Rlt" );

        desc6.putUnitDouble( idHrzn, idRlt, 0.000000 );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idRlt = charIDToTypeID( "#Rlt" );

        desc6.putUnitDouble( idVrtc, idRlt, 0.000000 );

    var idOfst = charIDToTypeID( "Ofst" );

    desc4.putObject( idOfst, idOfst, desc6 );

    var idAntA = charIDToTypeID( "AntA" );

    desc4.putBoolean( idAntA, true );

executeAction( idPlc, desc4, DialogModes.NO );

// toggle visibility of others;

// =======================================================

var idShw = charIDToTypeID( "Shw " );

    var desc10 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var list4 = new ActionList();

            var ref7 = new ActionReference();

            var idLyr = charIDToTypeID( "Lyr " );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref7.putEnumerated( idLyr, idOrdn, idTrgt );

        list4.putReference( ref7 );

    desc10.putList( idnull, list4 );

    var idTglO = charIDToTypeID( "TglO" );

    desc10.putBoolean( idTglO, true );

executeAction( idShw, desc10, DialogModes.NO );

// close;

app.activeDocument.close(SaveOptions.SAVECHANGES)

};

};

edited

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
Reply
Loading...
Community Beginner ,
May 20, 2014

Copy link to clipboard

Copied

Hi! Where exactly and how would I place the code to save for a jpeg after the process has been done? I've been using the code you posted here and it saves as a psd.  I tried pasting that other jpeg code but couldn't figure out where it goes.  So sorry as I'm not familiar with coding.

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
Reply
Loading...
LEGEND ,
May 21, 2014

Copy link to clipboard

Copied

What code are you using and trying to combine exactly?

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
Reply
Loading...
Community Beginner ,
May 23, 2014

Copy link to clipboard

Copied

This one below.  I copied the select to folder and that worked but the save to jpeg I couldn't figure it out   love the script thou!

Only thing is instead of saving for psd I'd like it to save for jpg at "8" quality, same resolution.

// replace smart object’s content and save psd;

// 2011, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

var thePath = myDocument.path;

var theLayer = myDocument.activeLayer;

// psd options;

psdOpts = new PhotoshopSaveOptions();

psdOpts.embedColorProfile = true;

psdOpts.alphaChannels = true;

psdOpts.layers = true;

psdOpts.spotColors = true;

// check if layer is smart object;

if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}

else {

// select files;

if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.psd;*.tif;*.jpg", true)}

else {var theFiles = File.openDialog ("please select files", getFiles, true)};

if (theFiles) {

// work through the array;

          for (var m = 0; m < theFiles.length; m++) {

// replace smart object;

                    theLayer = replaceContents (theFiles, theLayer);

                    var theNewName = theFiles.name.match(/(.*)\.[^\.]+$/)[1];

//save jpg;

                    myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".psd")),psdOpts,true);

                    }

          }

}

};

////// get psds, tifs and jpgs from files //////

function getFiles (theFile) {

     if (theFile.name.match(/\.(psd|tif)$/i) != null || theFile.constructor.name == "Folder") {

          return true

          };

     };

////// replace contents //////

function replaceContents (newFile, theSO) {

app.activeDocument.activeLayer = theSO;

// =======================================================

var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );

    var desc3 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc3.putPath( idnull, new File( newFile ) );

    var idPgNm = charIDToTypeID( "PgNm" );

    desc3.putInteger( idPgNm, 1 );

executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );

return app.activeDocument.activeLayer

};

THANK YOU!!!!

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
Reply
Loading...
LEGEND ,
May 24, 2014

Copy link to clipboard

Copied

Please try

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

var thePath = myDocument.path;

var theLayer = myDocument.activeLayer;

// jpg options;

var jpgopts = new JPEGSaveOptions();

jpgopts.embedProfile = true;

jpgopts.formatOptions = FormatOptions.STANDARDBASELINE;

jpgopts.matte = MatteType.NONE;

jpgopts.quality = 8;

// check if layer is smart object;

if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}

else {

// select files;

if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.psd;*.tif;*.jpg", true)}

else {var theFiles = File.openDialog ("please select files", getFiles, true)};

if (theFiles) {

// work through the array;

          for (var m = 0; m < theFiles.length; m++) {

// replace smart object;

                    theLayer = replaceContents (theFiles, theLayer);

                    var theNewName = theFiles.name.match(/(.*)\.[^\.]+$/)[1];

//save jpg;

                    myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".jpg")),jpgopts,true);

                    }

          }

}

};

////// get psds, tifs and jpgs from files //////

function getFiles (theFile) {

     if (theFile.name.match(/\.(psd|tif)$/i) != null || theFile.constructor.name == "Folder") {

          return true

          };

     };

////// replace contents //////

function replaceContents (newFile, theSO) {

app.activeDocument.activeLayer = theSO;

// =======================================================

var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );

    var desc3 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc3.putPath( idnull, new File( newFile ) );

    var idPgNm = charIDToTypeID( "PgNm" );

    desc3.putInteger( idPgNm, 1 );

executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );

return app.activeDocument.activeLayer

};

Likes

3 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
Reply
Loading...
Most Valuable Participant ,
Jan 31, 2014

Copy link to clipboard

Copied

SamanthaLee706 wrote:

Hello,

This is what I have:

  • a mockup file of a book with the cover image set as a transformed smart object
  • a folder of images resized to fit said smart object

This is what I would like a script to do (if possible):

  • for every image in said folder
  • replace smart object with images
  • save each new mockup (one for each new image) as a PSD file.

We have to create over 40 book, CD, DVD, and Blu-Ray mockups for each flyer we do.  Smart Objects help streamline it a little but I'm just going through and using an action right now, which I know is less than ideal.  I don't mind if the file names aren't what I need them to be, so incremental file naming would be fine because I could rename them all later.

Any suggestions on how I could streamline this process without having to manually replace and save?

You should be able to do what you want using Photoshop Data driven graphics with a PSD template with defined variables and a CSV file.  If you don't want to use that or create CSV files.  A simple template psd file and a script can also do what you want. 

If you look at my Photo Collage Toolkit for Photoshop you will find it contains a some batch scripts. BatchOneImageCollage, BatchMultiImageCollage and BatchPicturePackage to batch populate collage templates.

Photo Collage Toolkit.

Photoshop scripting is powerful and I believe this package demonstrates this.

The package includes four simple rules to follow when making Photo Collage Template PSD files so they will be compatible with my Photoshop scripts.

There are twelve scripts in this package they provide the following functions:

  1. TestCollageTemplate.jsx - Used to test a Photo Collage Template while you are making it with Photoshop.
  2. CollageTemplateBuilder.jsx - Can build Templates compatible with this toolkit's scripts.
  3. LayerToAlphaChan.jsx - Used to convert a Prototype Image Layer stack into a template document.
  4. InteractivePopulateCollage.jsx - Used to interactively populate Any Photo Collage template. Offers most user control inserting pictures and text.
  5. ReplaceCollageImage.jsx - use to replace a populated collage image Smart Object layer with an other image correctly resized and positioned.
  6. ChangeTextSize.jsx - This script can be used to change Image stamps text size when the size used by the populating did not work well.
  7. PopulateCollageTemplate.jsx - Used to Automatically populate a Photo Collage template and leave the populated copy open in Photoshop.
  8. BatchOneImageCollage.jsx - Used to Automatically Batch Populate Collage templates that only have one image inserted. The Collage or Image may be stamped with text.
  9. BatchMultiImageCollage.jsx - Used to Automatically Batch Populate Any Photo Collage template with images in a source image folder. Easier to use than the interactive script. Saved collages can be tweaked.
  10. BatchPicturePackage.jsx - Used to Automatically Batch Populate Any Photo Collage template with an image in a source image folder
  11. PasteImageRoll.jsx - Paste Images into a document to be print on roll paper.
  12. PCTpreferences.jsx - Edit This File to Customize Collage Populating scripts default setting and add your own Layer styles.


Documentation and Examples

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
Reply
Loading...
Community Beginner ,
Jan 31, 2014

Copy link to clipboard

Copied

Tried 'BatchOneImageCollage" before and this is what popped up:

Screen Shot 2014-01-31 at 10.44.35 AM.jpg

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
Reply
Loading...
Most Valuable Participant ,
Jan 31, 2014

Copy link to clipboard

Copied

Try running the script from Photoshop instead of the extendscript toolkit it has some issues or comment out "#target photoshop".  Also note my Scripts place in files from a straight on perspective.  Image areas can have any shape and appear to have a perspective like your covers.  However to achieve the correct perspective the image needs to have it to begin with or the placed smart object layer needs to have their associated transform tweaked to have the corners matched with the area.  If the cover perspective is not extreme the placed images may look good without tweaking the transform.. Any size image will be resized to fit the image location.  The script work best when image and image areas have the same aspect ratios,  However they don't need to be.

Since you have only a single image and all your source images are the same size and resolution.  You can write a Batch script that would replace the smart object layers embedded object in a template with a placed and transformed image the script just needs to know the name of the template's smart object layer.  All source images would need to be exactly the same size and resolution. You would need a template psd file for each image size you want to use.

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
Reply
Loading...
New Here ,
May 27, 2016

Copy link to clipboard

Copied

Hello there,

I have a question to this script.

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

var thePath = myDocument.path;

var theLayer = myDocument.activeLayer;

// jpg options;

var jpgopts = new JPEGSaveOptions();

jpgopts.embedProfile = true;

jpgopts.formatOptions = FormatOptions.STANDARDBASELINE;

jpgopts.matte = MatteType.NONE;

jpgopts.quality = 8;

// check if layer is smart object;

if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}

else {

// select files;

if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.psd;*.tif;*.jpg", true)}

else {var theFiles = File.openDialog ("please select files", getFiles, true)};

if (theFiles) {

// work through the array;

          for (var m = 0; m < theFiles.length; m++) {

// replace smart object;

                    theLayer = replaceContents (theFiles, theLayer);

                    var theNewName = theFiles.name.match(/(.*)\.[^\.]+$/)[1];

//save jpg;

                    myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".jpg")),jpgopts,true);

                    }

          }

}

};

////// get psds, tifs and jpgs from files //////

function getFiles (theFile) {

     if (theFile.name.match(/\.(psd|tif)$/i) != null || theFile.constructor.name == "Folder") {

          return true

          };

     };

////// replace contents //////

function replaceContents (newFile, theSO) {

app.activeDocument.activeLayer = theSO;

// =======================================================

var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );

    var desc3 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc3.putPath( idnull, new File( newFile ) );

    var idPgNm = charIDToTypeID( "PgNm" );

    desc3.putInteger( idPgNm, 1 );

executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );

return app.activeDocument.activeLayer

};

I´m not a coder and would like to know if someone know how to replace the following part of the code:

// select files;

if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.psd;*.tif;*.jpg", true)}

else {var theFiles = File.openDialog ("please select files", getFiles, true)};

if (theFiles) {

I would like to have the script running without asking to select the files. I would like to define a folder directly within the script. For example, C:/documents/images/...

so that the script immediatly starts without asking for anything.

Can anybody help me out ?

Best wishes

Olli

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
Reply
Loading...
LEGEND ,
May 27, 2016

Copy link to clipboard

Copied

You could try

var theFiles = Folder(/* insert the correct path here */).getFiles(/\.(jpg|tif|psd)$/i);

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
Reply
Loading...
New Here ,
May 27, 2016

Copy link to clipboard

Copied

Thank you so much for your reply.

I tried it but it did not work

.......

// select files;

if ($.os.search(/windows/i) != -1) {var theFiles = Folder(/E:\images\).getFiles(/\.(jpg|tif|psd)$/i)}

else {var theFiles = File.openDialog ("please select files", getFiles, true)};

if (theFiles) {

// work through the array;

.......

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
Reply
Loading...
LEGEND ,
May 27, 2016

Copy link to clipboard

Copied

You have not marked the String as a String by putting it in inverted commas.

var theFiles = Folder"(/E:\images\").getFiles(/\.(jpg|tif|psd)$/i)

and as I am no Windows user I am not sure about the slashes you used.

Likes

1 Like

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
Reply
Loading...
Guide ,
May 27, 2016

Copy link to clipboard

Copied

var theFiles = Folder("/e/images").getFiles(/\.(jpg|tif|psd)$/i);

Likes

1 Like

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
Reply
Loading...
New Here ,
May 27, 2016

Copy link to clipboard

Copied

THANK YOU !!! It worked

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
Reply
Loading...
LEGEND ,
May 27, 2016

Copy link to clipboard

Copied

And I even typo-ed the first inverted comma before the bracket …

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
Reply
Loading...
Community Beginner ,
Dec 11, 2016

Copy link to clipboard

Copied

Hello, when i try to apply the script i got error, how to fix this, thanks2016-12-11 23_47_12-Error.jpg

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
Reply
Loading...
Guide ,
Dec 11, 2016

Copy link to clipboard

Copied

The file needs to be saved before running 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
Reply
Loading...
Community Beginner ,
Dec 11, 2016

Copy link to clipboard

Copied

Thank You!!

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
Reply
Loading...
New Here ,
Dec 08, 2016

Copy link to clipboard

Copied

How would I modify this script to replace multiple (and separate) smart objects in one PSD before it saves out each time.  I'm thinking it would ask for the user to define which files will replace each smart object as it cycles through. But, I do not know how to make the code prompt for all smart objects before it begins saving out.  Thanks for any help!

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
Reply
Loading...
New Here ,
Jan 13, 2017

Copy link to clipboard

Copied

How Can I Use This Script Just Copy Paste Or Edit Something Can Please Recommend Some Tutorial

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
Reply
Loading...