What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

File automation


JimboHames

Member
Messages
7
Likes
2
File automation, copying layers to other open doc, close doc, and loop through other source files

I have a script which I feel is so close to working but I'm at the point where I'm pulling my hair out.
Let me give you a rundown.

I have a folder of Source PSD and a folder of Destination TIFF files.
The script runs and opens a source file then searches the Destination folder for a file which contains the name of the Source file and opens that.

I then need the script to copy the background layer from the Destination TIFF file over to the Source file
Delete Layer 1 in the Source file (Copied layer should be named Layer 2)

Save as PSD in Destination Folder using the same name as original Destination file

Close open docs

Then repeat for all other Source files
Right now it seems to want to save the original Destination file and refuses to cycle through the additional Source images

The script I have is this:-

// Prompt user to select Source and Destination folders
var sourceFolder = Folder.selectDialog("Select Source Folder");
var destFolder = Folder.selectDialog("Select Destination Folder");

if (sourceFolder && destFolder) {
var sourceFiles = sourceFolder.getFiles("*.psd");
var destFiles = destFolder.getFiles("*.tif");

for (var i = 0; i < sourceFiles.length; i++) {
var sourceFile = sourceFiles;
var sourceFileName = sourceFile.name.replace(/\.[^.]+$/, ""); // Remove extension

for (var j = 0; j < destFiles.length; j++) {
var destFile = destFiles[j];
var destFileName = destFile.name.replace(/\.[^.]+$/, ""); // Remove extension

if (destFileName.indexOf(sourceFileName) !== -1) {
var sourceDoc = app.open(sourceFile);
var destDoc = app.open(destFile);

// Delete Layer 1 in source document
if (sourceDoc.layers.length > 0) {
sourceDoc.layers[sourceDoc.layers.length - 1].remove();
}

// Duplicate the background layer from destination
var destBackgroundLayer = destDoc.artLayers[0];
var sourceLayer = destBackgroundLayer.duplicate(sourceDoc, ElementPlacement.PLACEATBEGINNING);

// Loop through layers in source document
for (var k = sourceDoc.layers.length - 1; k >= 0; k--) {
var sourceChildLayer = sourceDoc.layers[k];
var sourceParentLayer = sourceChildLayer.parent;

// Check if the source layer is a clipping mask
if (sourceChildLayer.grouped && sourceParentLayer) {
// Find the corresponding parent layer in destination
var destParentLayerName = sourceParentLayer.name;
var destParentLayer = destDoc.layers.getByName(destParentLayerName);

if (destParentLayer) {
sourceChildLayer.duplicate(destParentLayer, ElementPlacement.PLACEATBEGINNING);
}
}
}

// Save modified source file in destination folder with PSD file name
var newFileName = sourceFileName + "_modified.psd";
sourceDoc.saveAs(new File(destFolder + "/" + newFileName), SaveOptions.PSD);

sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
destDoc.close(SaveOptions.DONOTSAVECHANGES);

break; // Once matched, move to the next source file
}
}
}
} else {
alert("Please select both Source and Destination folders.");
}



~ appreciate any help!
 
Below is a slightly tweaked version of your code.
This doesn't give me any errors using CC 2019 on Win10x64:


JavaScript:
// Prompt user to select Source and Destination folders
var sourceFolder = Folder.selectDialog("Select Source Folder");
var destFolder = Folder.selectDialog("Select Destination Folder");

if (sourceFolder && destFolder) {
var sourceFiles = sourceFolder.getFiles("*.psd");
var destFiles = destFolder.getFiles("*.tif");

for (var i = 0; i < sourceFiles.length; i++) {
var sourceFile = new File(sourceFiles[i]);                                                                    // ** EDITED **
var sourceFileName = sourceFile.name.replace(/\.[^.]+$/, ""); // Remove extension

for (var j = 0; j < destFiles.length; j++) {
var destFile = destFiles[j];
var destFileName = destFile.name.replace(/\.[^.]+$/, ""); // Remove extension

if (destFileName.indexOf(sourceFileName) !== -1) {
var sourceDoc = app.open(sourceFile);              
var destDoc = app.open(destFile);          

// Duplicate the background layer from destination
var destBackgroundLayer = destDoc.artLayers[0];                                                              // ** BLOCK MOVED TO BEFORE 'DELETE LAYER 1' **
var sourceLayer = destBackgroundLayer.duplicate(sourceDoc, ElementPlacement.PLACEATBEGINNING);
app.activeDocument = sourceDoc;              

// Delete Layer 1 in source document
if (sourceDoc.layers.length > 0) {                                                                           // ** BLOCK MOVED TO AFTER 'DUPLICATE LAYER' **
sourceDoc.layers[sourceDoc.layers.length - 1].remove();
}

// Loop through layers in source document
for (var k = sourceDoc.layers.length - 1; k >= 0; k--) {
var sourceChildLayer = sourceDoc.layers[k];
var sourceParentLayer = sourceChildLayer.parent;

// Check if the source layer is a clipping mask
if (sourceChildLayer.grouped && sourceParentLayer) {
// Find the corresponding parent layer in destination
var destParentLayerName = sourceParentLayer.name;
var destParentLayer = destDoc.layers.getByName(destParentLayerName);

if (destParentLayer) {
sourceChildLayer.duplicate(destParentLayer, ElementPlacement.PLACEATBEGINNING);
}
}
}

// Save modified source file in destination folder with PSD file name
var newFileName = sourceFileName + "_modified.psd";
var saveName = new File(decodeURI(destFolder + "/" + newFileName));                            // ** EDITED **
sourceDoc.saveAs(saveName);                                                                     // ** EDITED **

sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
destDoc.close(SaveOptions.DONOTSAVECHANGES);

// break; // Once matched, move to the next source file                                       // ** NOT REQUIRED **
}
}
}
} else {
alert("Please select both Source and Destination folders.");
}


Regards.
MrToM.
 
Below is a slightly tweaked version of your code.
This doesn't give me any errors using CC 2019 on Win10x64:


JavaScript:
// Prompt user to select Source and Destination folders
var sourceFolder = Folder.selectDialog("Select Source Folder");
var destFolder = Folder.selectDialog("Select Destination Folder");

if (sourceFolder && destFolder) {
var sourceFiles = sourceFolder.getFiles("*.psd");
var destFiles = destFolder.getFiles("*.tif");

for (var i = 0; i < sourceFiles.length; i++) {
var sourceFile = new File(sourceFiles[i]);                                                                    // ** EDITED **
var sourceFileName = sourceFile.name.replace(/\.[^.]+$/, ""); // Remove extension

for (var j = 0; j < destFiles.length; j++) {
var destFile = destFiles[j];
var destFileName = destFile.name.replace(/\.[^.]+$/, ""); // Remove extension

if (destFileName.indexOf(sourceFileName) !== -1) {
var sourceDoc = app.open(sourceFile);             
var destDoc = app.open(destFile);         

// Duplicate the background layer from destination
var destBackgroundLayer = destDoc.artLayers[0];                                                              // ** BLOCK MOVED TO BEFORE 'DELETE LAYER 1' **
var sourceLayer = destBackgroundLayer.duplicate(sourceDoc, ElementPlacement.PLACEATBEGINNING);
app.activeDocument = sourceDoc;             

// Delete Layer 1 in source document
if (sourceDoc.layers.length > 0) {                                                                           // ** BLOCK MOVED TO AFTER 'DUPLICATE LAYER' **
sourceDoc.layers[sourceDoc.layers.length - 1].remove();
}

// Loop through layers in source document
for (var k = sourceDoc.layers.length - 1; k >= 0; k--) {
var sourceChildLayer = sourceDoc.layers[k];
var sourceParentLayer = sourceChildLayer.parent;

// Check if the source layer is a clipping mask
if (sourceChildLayer.grouped && sourceParentLayer) {
// Find the corresponding parent layer in destination
var destParentLayerName = sourceParentLayer.name;
var destParentLayer = destDoc.layers.getByName(destParentLayerName);

if (destParentLayer) {
sourceChildLayer.duplicate(destParentLayer, ElementPlacement.PLACEATBEGINNING);
}
}
}

// Save modified source file in destination folder with PSD file name
var newFileName = sourceFileName + "_modified.psd";
var saveName = new File(decodeURI(destFolder + "/" + newFileName));                            // ** EDITED **
sourceDoc.saveAs(saveName);                                                                     // ** EDITED **

sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
destDoc.close(SaveOptions.DONOTSAVECHANGES);

// break; // Once matched, move to the next source file                                       // ** NOT REQUIRED **
}
}
}
} else {
alert("Please select both Source and Destination folders.");
}


Regards.
MrToM.
You sir are a gentleman and a scholar!
It works!!

Only thing is I still can't get it to save using the name of the Destination file and not the source one.

Any ideas. I've tried a couple edits but nada

No worries if not, I can always rename manually!
 
Only thing is I still can't get it to save using the name of the Destination file and not the source one.

Ah! Sorry, I was under the impression that the filenames were the same but the 'tif' filename only contains the psd filename...right?

If that's the case then this should fix it:

JSX:
// Prompt user to select Source and Destination folders
var sourceFolder = Folder.selectDialog("Select Source Folder");
var destFolder = Folder.selectDialog("Select Destination Folder");

if (sourceFolder && destFolder) {
var sourceFiles = sourceFolder.getFiles("*.psd");
var destFiles = destFolder.getFiles("*.tif");

for (var i = 0; i < sourceFiles.length; i++) {
var sourceFile = new File(sourceFiles);                                                                    // ** EDITED **
var sourceFileName = sourceFile.name.replace(/\.[^.]+$/, ""); // Remove extension

for (var j = 0; j < destFiles.length; j++) {
var destFile = destFiles[j];
var destFileName = destFile.name.replace(/\.[^.]+$/, ""); // Remove extension

if (destFileName.indexOf(sourceFileName) !== -1) {
var sourceDoc = app.open(sourceFile);             
var destDoc = app.open(destFile);         

// Duplicate the background layer from destination
var destBackgroundLayer = destDoc.artLayers[0];                                                              // ** BLOCK MOVED TO BEFORE 'DELETE LAYER 1' **
var sourceLayer = destBackgroundLayer.duplicate(sourceDoc, ElementPlacement.PLACEATBEGINNING);
app.activeDocument = sourceDoc;                                                                             // ** ADDED **

// Delete Layer 1 in source document
if (sourceDoc.layers.length > 0) {                                                                          // ** BLOCK MOVED TO AFTER 'DUPLICATE LAYER' **
sourceDoc.layers[sourceDoc.layers.length - 1].remove();
}

// Loop through layers in source document
for (var k = sourceDoc.layers.length - 1; k >= 0; k--) {
var sourceChildLayer = sourceDoc.layers[k];
var sourceParentLayer = sourceChildLayer.parent;

// Check if the source layer is a clipping mask
if (sourceChildLayer.grouped && sourceParentLayer) {
// Find the corresponding parent layer in destination
var destParentLayerName = sourceParentLayer.name;
var destParentLayer = destDoc.layers.getByName(destParentLayerName);

if (destParentLayer) {
sourceChildLayer.duplicate(destParentLayer, ElementPlacement.PLACEATBEGINNING);
}
}
}

// Save modified source file in destination folder with PSD file name
var newFileName = destFileName + "_modified.psd";                                                // ** CHANGED 'sourceFileName' TO 'destFileName'  **
var saveName = new File(decodeURI(destFolder + "/" + newFileName));                            // ** EDITED **
sourceDoc.saveAs(saveName);                                                                     // ** EDITED **

sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
destDoc.close(SaveOptions.DONOTSAVECHANGES);

// break; // Once matched, move to the next source file                                       // ** NOT REQUIRED **
}
}
}
} else {
alert("Please select both Source and Destination folders.");
}

Sorry for the missunderstanding.

Regards.
MrToM.
 
Hi Tom,
Thanks for giving it another look. You had changed line 7 which was causing an error but switching back fixed it and your other amend solved the issue with naming!

Can you help me with another problem?
I want to apply the alpha channel to layer 1 so it's transparent, do you know if there is a function for this?
I've struggled to find a solution.
Cheers!
 
Ah! Sorry, I was under the impression that the filenames were the same but the 'tif' filename only contains the psd filename...right?

If that's the case then this should fix it:

JSX:
// Prompt user to select Source and Destination folders
var sourceFolder = Folder.selectDialog("Select Source Folder");
var destFolder = Folder.selectDialog("Select Destination Folder");

if (sourceFolder && destFolder) {
var sourceFiles = sourceFolder.getFiles("*.psd");
var destFiles = destFolder.getFiles("*.tif");

for (var i = 0; i < sourceFiles.length; i++) {
var sourceFile = new File(sourceFiles);                                                                    // ** EDITED **
var sourceFileName = sourceFile.name.replace(/\.[^.]+$/, ""); // Remove extension

for (var j = 0; j < destFiles.length; j++) {
var destFile = destFiles[j];
var destFileName = destFile.name.replace(/\.[^.]+$/, ""); // Remove extension

if (destFileName.indexOf(sourceFileName) !== -1) {
var sourceDoc = app.open(sourceFile);           
var destDoc = app.open(destFile);       

// Duplicate the background layer from destination
var destBackgroundLayer = destDoc.artLayers[0];                                                              // ** BLOCK MOVED TO BEFORE 'DELETE LAYER 1' **
var sourceLayer = destBackgroundLayer.duplicate(sourceDoc, ElementPlacement.PLACEATBEGINNING);
app.activeDocument = sourceDoc;                                                                             // ** ADDED **

// Delete Layer 1 in source document
if (sourceDoc.layers.length > 0) {                                                                          // ** BLOCK MOVED TO AFTER 'DUPLICATE LAYER' **
sourceDoc.layers[sourceDoc.layers.length - 1].remove();
}

// Loop through layers in source document
for (var k = sourceDoc.layers.length - 1; k >= 0; k--) {
var sourceChildLayer = sourceDoc.layers[k];
var sourceParentLayer = sourceChildLayer.parent;

// Check if the source layer is a clipping mask
if (sourceChildLayer.grouped && sourceParentLayer) {
// Find the corresponding parent layer in destination
var destParentLayerName = sourceParentLayer.name;
var destParentLayer = destDoc.layers.getByName(destParentLayerName);

if (destParentLayer) {
sourceChildLayer.duplicate(destParentLayer, ElementPlacement.PLACEATBEGINNING);
}
}
}

// Save modified source file in destination folder with PSD file name
var newFileName = destFileName + "_modified.psd";                                                // ** CHANGED 'sourceFileName' TO 'destFileName'  **
var saveName = new File(decodeURI(destFolder + "/" + newFileName));                            // ** EDITED **
sourceDoc.saveAs(saveName);                                                                     // ** EDITED **

sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
destDoc.close(SaveOptions.DONOTSAVECHANGES);

// break; // Once matched, move to the next source file                                       // ** NOT REQUIRED **
}
}
}
} else {
alert("Please select both Source and Destination folders.");
}

Sorry for the missunderstanding.

Regards.
MrToM.
Hi Tom,
Thanks for giving it another look. You had changed line 7 which was causing an error but switching back fixed it and your other amend solved the issue with naming!

Can you help me with another problem?
I want to apply the alpha channel to layer 1 so it's got a transparent background, do you know if there is a function for this?
I've struggled to find a solution.

I have tried creating an extra folder filled with the black and white alpha as a layer. And then applying this as a mask to the layer and then applying it.

However no luck :(

Will attach the amends I tried making. Do you know a better solution? Either using the Alpha Channel already in the file or the method with a folder of Masks. Either is fine.
Cheers!

// Prompt user to select Source, Destination, and Mask folders
var sourceFolder = Folder.selectDialog("Select Source Folder");
var destFolder = Folder.selectDialog("Select Destination Folder");
var maskFolder = Folder.selectDialog("Select Mask Folder");

if (sourceFolder && destFolder && maskFolder) {
var sourceFiles = sourceFolder.getFiles("*.psd");
var destFiles = destFolder.getFiles("*.tif");
var maskFiles = maskFolder.getFiles("*.psd");

for (var i = 0; i < sourceFiles.length; i++) {
var sourceFile = new File(sourceFiles);
var sourceFileName = sourceFile.name.replace(/\.[^.]+$/, "");

for (var j = 0; j < destFiles.length; j++) {
var destFile = destFiles[j];
var destFileName = destFile.name.replace(/\.[^.]+$/, "");

if (destFileName.indexOf(sourceFileName) !== -1) {
var sourceDoc = app.open(sourceFile);
var destDoc = app.open(destFile);

// Duplicate the background layer from destination
var destBackgroundLayer = destDoc.artLayers[0];
var sourceLayer = destBackgroundLayer.duplicate(sourceDoc, ElementPlacement.PLACEATBEGINNING);
app.activeDocument = sourceDoc;

// Delete Layer 1 in source document
if (sourceDoc.layers.length > 0) {
sourceDoc.layers[sourceDoc.layers.length - 1].remove();
}

// Loop through layers in source document
for (var k = sourceDoc.layers.length - 1; k >= 0; k--) {
var sourceChildLayer = sourceDoc.layers[k];
var sourceParentLayer = sourceChildLayer.parent;

// Check if the source layer is a clipping mask
if (sourceChildLayer.grouped && sourceParentLayer) {
var destParentLayerName = sourceParentLayer.name;
var destParentLayer = destDoc.layers.getByName(destParentLayerName);

if (destParentLayer) {
sourceChildLayer.duplicate(destParentLayer, ElementPlacement.PLACEATBEGINNING);
}
}
}

// Apply layer mask from mask folder
var maskFileName = sourceFileName + "_mask.psd";
var maskFilePath = maskFolder + "/" + maskFileName;
var maskFile = new File(maskFilePath);

if (maskFile.exists) {
var maskLayer = sourceDoc.artLayers.add();
maskLayer.name = "Mask Layer";
maskLayer.place(maskFile);

// Apply mask to the duplicated layer
sourceLayer = sourceDoc.activeLayer;
sourceLayer.applyLayerMask();
}

// Save modified source file in destination folder with PSD file name
var newFileName = destFileName + ".psd";
var saveName = new File(decodeURI(destFolder + "/" + newFileName));
sourceDoc.saveAs(saveName);
sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
destDoc.close(SaveOptions.DONOTSAVECHANGES);
}
}
}
} else {
alert("Please select Source, Destination, and Mask folders.");
}
 
You had changed line 7 which was causing an error...
I did, BUT this was all based on the code I copied from your initial post...which is wrong...but it's not your fault, nor mine.....here's why!
It took a while to notice what was going on but I think we've both been kobbled.

The actual code I wrote for line 7 was:
Code:
var sourceFile = new File(sourceFiles[i]);
You can see this in my first reply, but notice the difference in that line in my second.

I did wonder at the time when first reading your post why it turned italised but can you see WHERE it turns into italics?
Exactly at the point where you use 'i' as a var, enclosed in brackets.....which is the forum tags for 'italics'.

You should really use the code tags when posting code but as my second post proves even that isn't guaranteed not to fail.
Best practice is not to 'post' code at all but to 'attach' the .jsx file...although even then you'll have to zip it.

...but switching back fixed it...
Indeed it would, and had it have been displayed properly in the first place I wouldn't have even had the need to change it.

and your other amend solved the issue with naming!
Excellent.

Can you help me with another problem?
Sure....don't scratch it and put plenty of cream on.

I want to apply the alpha channel to layer 1 so it's transparent, do you know if there is a function for this?
Oh right, not that sort of problem.

Not sure exactly what you mean by this, 'apply the alpha channel'...???

Wouldn't this be the same as just deleting 'Layer 1' and adding a new blank layer, and possibly renaming it?

I can take a look but it would be helpful to have some sample files to work with and a clear description on what you want to do, with reference to those files.
Knowing your OS and PS version would also help, as I can make absolutely sure the code works with that version. (Although I can only test on Windows)

Your next post has popped up while writing this so there may be some crossover.....I'll post this then read it.

Regards.
MrToM.
 
Hi @JimboHames
Perfect timing....with ref to my previous post notice the error in line 7.....AGAIN!

Post your code in 'code' tags or zip the .jsx file and attach that.
(PS. This forum uses a different procedure for posting code, you need to click the 'code' tag FIRST, then paste your code into the pop-up, instead of the more usual way of pasting the code, highlighting it and then applying 'code' tags.)

Then, maybe, we can both start with the same code.

Regards.
MrToM.
 
Hi Tom,
Thanks for giving it another look. You had changed line 7 which was causing an error but switching back fixed it and your other amend solved the issue with naming!

Can you help me with another problem?
I want to apply the alpha channel to layer 1 so it's transparent, do you know if there is a function for this?
I've struggled to find a solution.
Cheers!

I did, BUT this was all based on the code I copied from your initial post...which is wrong...but it's not your fault, nor mine.....here's why!
It took a while to notice what was going on but I think we've both been kobbled.

The actual code I wrote for line 7 was:
Code:
var sourceFile = new File(sourceFiles[i]);
You can see this in my first reply, but notice the difference in that line in my second.

I did wonder at the time when first reading your post why it turned italised but can you see WHERE it turns into italics?
Exactly at the point where you use 'i' as a var, enclosed in brackets.....which is the forum tags for 'italics'.

You should really use the code tags when posting code but as my second post proves even that isn't guaranteed not to fail.
Best practice is not to 'post' code at all but to 'attach' the .jsx file...although even then you'll have to zip it.


Indeed it would, and had it have been displayed properly in the first place I wouldn't have even had the need to change it.


Excellent.


Sure....don't scratch it and put plenty of cream on.


Oh right, not that sort of problem.

Not sure exactly what you mean by this, 'apply the alpha channel'...???

Wouldn't this be the same as just deleting 'Layer 1' and adding a new blank layer, and possibly renaming it?

I can take a look but it would be helpful to have some sample files to work with and a clear description on what you want to do, with reference to those files.
Knowing your OS and PS version would also help, as I can make absolutely sure the code works with that version. (Although I can only test on Windows)

Your next post has popped up while writing this so there may be some crossover.....I'll post this then read it.

Regards.
MrToM.

AHA, so that's what happened! I was unsure why that bit had changed and just wanted to make you aware :)

Thank you for the lesson in best practice. I'm not one who's usually very active on forums but will endeavor to be better haha.

Ok so I am including some example files so you can hopefully get a better idea of what I'm asking.

In the source file there is an RGB layer, In the channels there is a Alpha 1 layer, And in PATHS there is a clipping Path.

So the main purpose of the script was to ensure the 'destination' files have the Clipping path. Which is why we are copying over the RGB layer from the Tif to the PSD.

However as these were output as TIF the layer has been flattened to not include transparent pixels (white background). (limitation of the process we are using unfortunately and no way around it)

I'm hoping once we have copied the RGB layer over we can then use that Alpha Channel to delete that White background in the main layer or apply it as a mask?

As I couldn't find a solution for using the Alpha Channel I instead created a 3rd folder 'MASKS' Hoping I could use that as a way to apply the Mask.

Again no luck (I'm a noob scripter)

So I'm asking if you know a way to achieve the above in either of the ways outlined.

Using that Alpha Channel or a seperate file.

Thank you for baring with me. Your help has been extremely appreciated!

Regards Jimbo
 

Attachments

  • TOM.zip
    14.9 MB · Views: 2
AHA, so that's what happened!
Yep! As if it isn't difficult enough!

Ok so I am including some example files so you can hopefully get a better idea of what I'm asking.
Excellent, thank-you.

Still no word on your PS version though, is it a closely guarded secret?

I'll digest all that info and have a think.

Thank you for baring with me. Your help has been extremely appreciated!

No worries.
At least now we're both working on the same code.

Regards.
MrToM.
 
Yep! As if it isn't difficult enough!


Excellent, thank-you.

Still no word on your PS version though, is it a closely guarded secret?

I'll digest all that info and have a think.



No worries.
At least now we're both working on the same code.

Regards.
MrToM.
Knew I'd forgot something!

Photoshop 2022 23.5.3
 
Right.

This is a bit confusing as the .jsx file you posted doesn't quite match the 'goal' we've been working toward so far, so the attached script still aims toward the original request, ish.
I've completely re-written it in order to keep it as easy to add or delete stuff you do or do not want.
It's commented throughout so If you want to edit it yourself you shouldn't have any trouble identifying what each section does.

In a nutshell, the script:
01. Opens a 'psd' and 'tif' file based on the filenames.
02. Extracts and copies the 'path' in the 'psd' file.
03. Pastes the 'path' into the 'tif' file. (Inc if it has a locked 'background' layer)
04. Creates a vector mask using the path. (Removes (hides) 'background')
05. Saves the 'tif' source file using the psd filename with '_modified' added to it and as a 'psd' in the selected 'tif' folder.

It doesn't name any layers 'Layer 2' nor delete any layers from the psd, in fact the psd is left untouched.

I wasn't sure if these were still a requirement.
Should be pretty simple to add though if required.

See how it goes for now.

Used PS 2022 (23.5.2.751)

Regards.
MrToM.
 

Attachments

  • COPY-PSD-TIF-MT_02.zip
    1.4 KB · Views: 1
Hiya Tom,

Looks like you took the script to the next level.. A level above my understanding but your annotation helps a lot!

Unfortunately I think we have gotten our wires crossed a bit. Let me try and explain as precisely as I can.

Source PSD has:-
Incorrect - RGB Layer
Correct - No White Background in RGB
Correct - Includes Channel named 'Alpha 1'
Correct - Includes Clipping Path named 'Path 1"

Tiff 'Destination' files have:-
Correct - RGB Layer
Incorrect - Includes White Background in RGB
Correct - Includes Channel named 'Alpha 1'
Incorrect - No Clipping Path named 'Path 1'

We are trying to align the Tif files to the Source PSD.

We were initially copying the RGB layer from Tif to PSD and deleting old RGB layer in PSD so that we gained the correct RGB and 'Path 1' Clipping Path.

However the Tiff file RGB we copied across also included the White Background.

The new version of the script:-

Fixes RGB background issue but we do not have the 'Path 1' Clipping Path in outputted file. as it's using the TIF file as the base.

Sorry to be a massive pain Tom my explanation in above post. wasn't the most clear.. you've been fantastic!
 
Hi Jimbo,

No worries.
Bit busy at the moment and away this afternoon but I'll get onto it as soon as.

Regards.
MrToM.
 
Right.

Not much has changed as what you wanted was there, (if you tilted your head and squinted), but admittedly it maybe wasn't as obvious as it could have been, and I did get the filename reversed, sorry.

Hopefully all fixed now.
You'll get a psd file, with the tif image, a transparent 'background', a channel named 'Alpha 1' and a path, (from the psd file), named 'Path 1'.

Open to further hair-pulling of course.

Regards.
MrToM.
 

Attachments

  • COPY-PSD-TIF-MT_03.zip
    1.5 KB · Views: 2

Back
Top