Copy link to clipboard
Copied
Hey guys, I'm asking again the same question. For some reason my question dissapeared after forum update.
So the idea is to combine together two psd files but keep the filename of the first image input.
Example : test-me-1.psd + test-me-5.psd = test-me-1.psd(final result)
I found this script here which does a pretty good job till the point of naming the end file : Line 125
theFile.saveAs(new File (theFolderThree + "/file" + bufferNumberWithZeros((a + 1), 4) ), psdOpts)
Would appreciate some help on how to tweek it so it could save it as I needed.
#target photoshop
// dialog for folder-selection;
var theFolderOne = Folder.selectDialog ("select a folder containing the backgoround images");
var theFolderTwo = Folder.selectDialog ("select a folder containing the foreground images");
var theFolderThree = Folder.selectDialog ("select a folder to save the combined images to");
if (theFolderOne && theFolderTwo && theFolderThree) {
var theFilesOne = theFolderOne.getFiles(checkFor);
var theFilesTwo = theFolderTwo.getFiles(checkFor);
// check if both folders contain the same number of files;
if (theFilesOne.length != theFilesTwo.length) {
alert ("the folders don’t contain the same number of images")
}
// else do the stuff;
else {
// create the psd-options;
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = false;
psdOpts.layers = true;
psdOpts.spotColors = true;
// run through the files;
for (var a = 0; a < theFilesOne.length; a++) {
// open background-image;
var theFile = app.open(File(theFilesOne[a]));
theFile.activeLayer = theFile.layers[0];
// place foreground-image;
var idPlc = charIDToTypeID( "Plc " );
var desc6 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc7 = new ActionDescriptor();
var idfsel = charIDToTypeID( "fsel" );
var idpdfSelection = stringIDToTypeID( "pdfSelection" );
var idpage = stringIDToTypeID( "page" );
desc7.putEnumerated( idfsel, idpdfSelection, idpage );
var idPgNm = charIDToTypeID( "PgNm" );
desc7.putInteger( idPgNm, 1 );
var idCrop = charIDToTypeID( "Crop" );
var idcropTo = stringIDToTypeID( "cropTo" );
var idboundingBox = stringIDToTypeID( "boundingBox" );
desc7.putEnumerated( idCrop, idcropTo, idboundingBox );
var idPDFG = charIDToTypeID( "PDFG" );
desc6.putObject( idAs, idPDFG, desc7 );
var idnull = charIDToTypeID( "null" );
desc6.putPath( idnull, new File( theFilesTwo[a] ) );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc6.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc8 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idRlt = charIDToTypeID( "#Rlt" );
desc8.putUnitDouble( idHrzn, idRlt, 0.000000 );
var idVrtc = charIDToTypeID( "Vrtc" );
var idRlt = charIDToTypeID( "#Rlt" );
desc8.putUnitDouble( idVrtc, idRlt, 0.000000 );
var idOfst = charIDToTypeID( "Ofst" );
desc6.putObject( idOfst, idOfst, desc8 );
var idAntA = charIDToTypeID( "AntA" );
desc6.putBoolean( idAntA, true );
executeAction( idPlc, desc6, DialogModes.NO );
// save the combined files;
theFile.saveAs(new File (theFolderThree + "/file" + bufferNumberWithZeros((a + 1), 4) ), psdOpts)
theFile.close(SaveOptions.DONOTSAVECHANGES)
}
}
};
////////////////////////////////////
////// check for psd, tif or jpg //////
function checkFor (theFile) {
if (theFile.name.slice(-4) == ".psd" || theFile.name.slice(-4) == ".tif" || theFile.name.slice(-4) == ".jpg") {return true}
else {return false}
};
////// buffer number with zeros //////
function bufferNumberWithZeros (number, places) {
var theNumberString = String(number);
for (var o = 0; o < (places - String(number).length); o++) {
theNumberString = String("0" + theNumberString)
};
return theNumberString
};
Copy link to clipboard
Copied
Moving to Photoshop Scripting
Edit: cancel that can't find the Photoshop Scripting forum
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Previous Adobe forums were powered by Jive where we could open directly subsection of some general forum.
For ex. current Photoshop 'Actions and Scripting' were under:
https://forums.adobe.com/community/photoshop/photoshop_scripting
while Bridge 'Scripting' under:
https://forums.adobe.com/community/bridge/bridge_scripting
Now to access them we have to click appropraite tab / label from main theme.
My question is what url / link to use to open directly subsection of the forum.
For ex. if I don't want to open first General Photoshop Forums, and then 'Actions and Scripting' but that second in no time?
Copy link to clipboard
Copied
Ged, this is sure a temporary situation. Least ways I hope it is. There are just 18 forums at the moment
The Overview pages had all sorts of invaluble links and information. with the Photoshop Overview pager being one of best examples. Where do we find that information now? Where do we send people when they ask about tablet setup as an example?
The Premeire Pro forum was another example with an amazing array of useful links on its Overview page.
OK, I have just discovered that if you tick all the options, the list expands dramatically.
Copy link to clipboard
Copied
Nice one Trevor, I was wondering where all the other forums where, now if only they would populate in alphabetical other 🙂
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I filled all boxes and still can't find XMP SDK forum:
https://forums.adobe.com/community/design_development/xmp_sdk
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The reason is all posts from between Aug, 22th - Sep, 9th weren't meant to be archived.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
theFile.saveAs(File(theFolderThree + '/' + theFile.name.split(/\./)[0]), psdOpts)
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Probably not everything works on this forum yet like on Jive. Visit this topic now and then to find new buttons which I hope Adobe is going to provide...
Copy link to clipboard
Copied
Hi Joshua,
There is a “Correct Answer” button at the bottom of each post. If you don’t see it, Expand the Replies or tell us which one to mark and we can do it for you.
Jane
Copy link to clipboard
Copied
joshuab10257965 – I have modified the code to save the combined file using the first input filename.
It seemed to work fine for a single image, however when combining multiple images, the order was messed up and the files were not "paired" correctly (if that is the expectation). I tried to include .sort() code without success.
// community.adobe.com/t5/Photoshop/Combine-two-psd-into-one-Keep-filename/td-p/10610400
#target photoshop
// dialog for folder-selection;
var theFolderOne = Folder.selectDialog ("select a folder containing the backgoround images");
var theFolderTwo = Folder.selectDialog ("select a folder containing the foreground images");
var theFolderThree = Folder.selectDialog ("select a folder to save the combined images to");
if (theFolderOne && theFolderTwo && theFolderThree) {
var theFilesOne = theFolderOne.getFiles(checkFor);
var theFilesTwo = theFolderTwo.getFiles(checkFor);
// check if both folders contain the same number of files;
if (theFilesOne.length != theFilesTwo.length) {
alert ("the folders don’t contain the same number of images")
}
// else do the stuff;
else {
// create the psd-options;
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = false;
psdOpts.layers = true;
psdOpts.spotColors = true;
// run through the files;
for (var a = 0; a < theFilesOne.length; a++) {
// open background-image;
var theFile = app.open(File(theFilesOne[a]));
theFile.activeLayer = theFile.layers[0];
// ADDED BY STEPHEN A. MARSH 2019: Capture the first filename to use when saving the combined file
var theFirstName = theFile.name.replace(/\.[^\.]+$/, '');
// place foreground-image;
var idPlc = charIDToTypeID( "Plc " );
var desc6 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc7 = new ActionDescriptor();
var idfsel = charIDToTypeID( "fsel" );
var idpdfSelection = stringIDToTypeID( "pdfSelection" );
var idpage = stringIDToTypeID( "page" );
desc7.putEnumerated( idfsel, idpdfSelection, idpage );
var idPgNm = charIDToTypeID( "PgNm" );
desc7.putInteger( idPgNm, 1 );
var idCrop = charIDToTypeID( "Crop" );
var idcropTo = stringIDToTypeID( "cropTo" );
var idboundingBox = stringIDToTypeID( "boundingBox" );
desc7.putEnumerated( idCrop, idcropTo, idboundingBox );
var idPDFG = charIDToTypeID( "PDFG" );
desc6.putObject( idAs, idPDFG, desc7 );
var idnull = charIDToTypeID( "null" );
desc6.putPath( idnull, new File( theFilesTwo[a] ) );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc6.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc8 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idRlt = charIDToTypeID( "#Rlt" );
desc8.putUnitDouble( idHrzn, idRlt, 0.000000 );
var idVrtc = charIDToTypeID( "Vrtc" );
var idRlt = charIDToTypeID( "#Rlt" );
desc8.putUnitDouble( idVrtc, idRlt, 0.000000 );
var idOfst = charIDToTypeID( "Ofst" );
desc6.putObject( idOfst, idOfst, desc8 );
var idAntA = charIDToTypeID( "AntA" );
desc6.putBoolean( idAntA, true );
executeAction( idPlc, desc6, DialogModes.NO );
// save the combined files;
// theFile.saveAs(new File (theFolderThree + "/file" + bufferNumberWithZeros((a + 1), 4) ), psdOpts)
// MODIFIED BY STEPHEN A. MARSH 2019: Use the first filename
theFile.saveAs(new File (theFolderThree + "/" + theFirstName ), psdOpts)
theFile.close(SaveOptions.DONOTSAVECHANGES)
}
}
};
////////////////////////////////////
////// check for psd, tif or jpg //////
function checkFor (theFile) {
if (theFile.name.slice(-4) == ".psd" || theFile.name.slice(-4) == ".tif" || theFile.name.slice(-4) == ".jpg") {return true}
else {return false}
};
////// buffer number with zeros //////
function bufferNumberWithZeros (number, places) {
var theNumberString = String(number);
for (var o = 0; o < (places - String(number).length); o++) {
theNumberString = String("0" + theNumberString)
};
return theNumberString
};