Copy link to clipboard
Copied
Hopefully someone can help. I need to create some type of script or action to do the following...
I have 8000+ images in one folder named as follows:
image1a.psd
image1b.psd
image2a.psd
image2b.psd
etc.
all the way to image 4000a.psd & image4000b.psd
I need to combine "image1a.psd" and "image1b.psd" as layers into a single .psd file for all 8000+ images.
How can I accomplish this?
Thanks!
1 Correct answer
I just realized that in the lastest version of PS, you can ungroup smart objects. So I changed the code to that it won't flatten the "b" image.
#target photoshop
var srcFolder = new Folder('~/desktop/combine-test/');
var mask = '*a.psd'
var fileList = srcFolder.getFiles (mask);
var psdOptions = new PhotoshopSaveOptions()
psdOptions.layers = true
for(var i=0;i<fileList.length;i++){
var sndFileName = fileList[i].name.substring (0, fileList[i].name.length-5)
var sndFile = new File(srcFolde
...
Explore related tutorials & articles
Copy link to clipboard
Copied
There have been some other requests like this. You might want to do a search and see if you can fine something that works for you.
Copy link to clipboard
Copied
Thank you, I have looked at other posts with similar questions, but have not yet been able to find a solution for my specific need...
Copy link to clipboard
Copied
So what are your specific needs? The easiest, would be to combine all the files and save them as a new file, then you can go back and do whatever editing you need to do.
Copy link to clipboard
Copied
Yes, I understand but to do that manually would take too long. For example, it takes me 30 seconds to open the files and combine layers, then save as a new file... working non-stop 8 hours / day it would take me 3 1/2 weeks to complete. Obviously I need an automated solution 😞
Copy link to clipboard
Copied
No, what I mean is if you combine the two files, what do you want to do with them? Of do you just want to combine the files and save?
Copy link to clipboard
Copied
Ah, I see... so I am combining the 2 layers together to run another script that creates an a\image as shown in the attachment. Basically taking 2 individual sides of a business card to create a realistic looking business card mockup for a shopping cart.
Copy link to clipboard
Copied
also do these files have multiple layers? if so do you flatten them or put them in a smart object?
Copy link to clipboard
Copied
Well, you can try this script. It will combine two file if the naming is how you state with the files ending in a and b. It will flatten the b file. You can comment out the rasterizing function (ras()) to leave it as a smart object. It will save the file as "c" in the same folder. You will need to change the folder name.
#target photoshop
var srcFolder = new Folder('~/desktop/combine-test/');
var mask = '*a.psd'
var fileList = srcFolder.getFiles (mask);
var psdOptions = new PhotoshopSaveOptions()
psdOptions.layers = true
for(var i=0;i<fileList.length;i++){
var sndFileName = fileList[i].name.substring (0, fileList[i].name.length-5)
var sndFile = new File(srcFolder + '/' + sndFileName + 'b.psd')
var doc = open(fileList[i]);
placeFile (sndFile);
ras ();
doc.saveAs (new File(srcFolder +'/' + sndFileName + 'c.psd'), psdOptions)
doc.close (SaveOptions.DONOTSAVECHANGES);
}
function placeFile(file){
var idPlc = charIDToTypeID( "Plc " );
var desc12 = new ActionDescriptor();
var idIdnt = charIDToTypeID( "Idnt" );
desc12.putInteger( idIdnt, 2 );
var idnull = charIDToTypeID( "null" );
desc12.putPath( idnull, new File( file ) );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc12.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc13 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc13.putUnitDouble( idHrzn, idPxl, 0.000000 );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc13.putUnitDouble( idVrtc, idPxl, 0.000000 );
var idOfst = charIDToTypeID( "Ofst" );
desc12.putObject( idOfst, idOfst, desc13 );
executeAction( idPlc, desc12, DialogModes.NO );
}
function ras(){
var idrasterizeLayer = stringIDToTypeID( "rasterizeLayer" );
var desc16 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1.putEnumerated( idLyr, idOrdn, idTrgt );
desc16.putReference( idnull, ref1 );
executeAction( idrasterizeLayer, desc16, DialogModes.NO );
}
Copy link to clipboard
Copied
Thank you, I will give it a try.
Copy link to clipboard
Copied
I just realized that in the lastest version of PS, you can ungroup smart objects. So I changed the code to that it won't flatten the "b" image.
#target photoshop
var srcFolder = new Folder('~/desktop/combine-test/');
var mask = '*a.psd'
var fileList = srcFolder.getFiles (mask);
var psdOptions = new PhotoshopSaveOptions()
psdOptions.layers = true
for(var i=0;i<fileList.length;i++){
var sndFileName = fileList[i].name.substring (0, fileList[i].name.length-5)
var sndFile = new File(srcFolder + '/' + sndFileName + 'b.psd')
var doc = open(fileList[i]);
placeFile (sndFile);
undoSO ();
doc.saveAs (new File(srcFolder +'/' + sndFileName + 'c.psd'), psdOptions)
doc.close (SaveOptions.DONOTSAVECHANGES);
}
function undoSO(){
var idplacedLayerConvertToLayers = stringIDToTypeID( "placedLayerConvertToLayers" );
executeAction( idplacedLayerConvertToLayers, undefined, DialogModes.NO );
var idungroupLayersEvent = stringIDToTypeID( "ungroupLayersEvent" );
var desc7 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref3 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref3.putEnumerated( idLyr, idOrdn, idTrgt );
desc7.putReference( idnull, ref3 );
executeAction( idungroupLayersEvent, desc7, DialogModes.NO );
}
function placeFile(file){
var idPlc = charIDToTypeID( "Plc " );
var desc12 = new ActionDescriptor();
var idIdnt = charIDToTypeID( "Idnt" );
desc12.putInteger( idIdnt, 2 );
var idnull = charIDToTypeID( "null" );
desc12.putPath( idnull, new File( file ) );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc12.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc13 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc13.putUnitDouble( idHrzn, idPxl, 0.000000 );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc13.putUnitDouble( idVrtc, idPxl, 0.000000 );
var idOfst = charIDToTypeID( "Ofst" );
desc12.putObject( idOfst, idOfst, desc13 );
executeAction( idPlc, desc12, DialogModes.NO );
}

