Copy link to clipboard
Copied
Hi there,
I’m new to posting in the community.
I’m hoping for some advice or assistance in setting up an action or a script to do the following.
I have a PSD template that I have set up an action to drop a PNG file into the bottom layer.
What I need is an automation of some sort that inserts the name of the Layer that I just dropped into the template to be added to the front of the PSD file name and saved as a jpeg for web.
I have just got my head around Actions, and Scripts are quite advanced for me. 🙂
Try the following script. You will need to record it as an action step, replacing any Save As/Export - Save for Web (Legacy) steps in the action.
/*
Export Save for Web Named After Visible Top-Level Layers.jsx
v1.0 - 21st May 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/layer-name-used-to-save-file-with-action-or-script/m-p/14630542
Info: Action helper script used to replace an action save/export step to include a custom filename using the visib...
I forgot to mention, that the other way to do this is to use Layer Comps, saving each comp with the name you require, then use the default Export Layer Comps to Files script.
https://helpx.adobe.com/au/photoshop/using/layer-comps.html
Copy link to clipboard
Copied
You'll need a script for the final save JPEG step, as including a layer name in the final file name is beyond actions or batch commands.
This could be a custom script, or an all purpose, generic layer saving script.
It might be better to have the whole action re-created as a script, rather than having a hybrid action that relies on a script? That is of course up to you, I'm happy to help, but I would need to see a screenshot of the action steps with each step expanded/disclosed and or have access to the action if it is too complicated to decipher from the screenshot.
When you "drop in" (how – File > Place or something else?) the PNG file into the template, what is the name of the layer? Is it the filename of the PNG? Can you post a screenshot of the layers panel?
Copy link to clipboard
Copied
Hey Stephen,
Thanks for replying.
Here is a Screen Shot.
The layer called Abstract Art 53 is the layer that I have dropped in.
I play an action that turns each folder on and off and saves it in jpg for web with the Abstract Art - 53 (or other files I drop in, in it's place) behind the folder layers.
What I am trying to achieve is to insert the Abstract - 53 layer name in front of the PSD files name when i run the action I mentioned above for saving the jpg.
DId that make sense?
Copy link to clipboard
Copied
OK, so it's a smart object layer....
As the name will vary, there needs to be a way to identify it in automation.
Is this the only smart object in the layer panel?
Will the smart object layer always be in the same absolute position in the layer stack?
Copy link to clipboard
Copied
I just checked the folders and yes that will be the only smart layer.
99% sure it will be in the same position.
Copy link to clipboard
Copied
Could you manually select the smart object layer? Or would the action that changes layer visibility also select layers and the smart object would no longer be selected at the save step.
Copy link to clipboard
Copied
The Smart Object Would always remain on, but the folders would turn on then off as the action saves them with the Smart Object behind (showing through transparent sections of the layers in the folders)
Copy link to clipboard
Copied
But will the SO layer be active/selected?
Can you post a screenshot of the layers panel after you run the action? If the SO layer isn't highlighted then I'll need different code to find the SO layer name.
Copy link to clipboard
Copied
Apoligies for the delay. I just needed to double check the action was working ok.
I've attached a screen shot.
To add to the file name saving I just released I also need the following format as it moves through the action.
"Smart Object Layer Name" - "Folder Layer Name" - PSD File Name.jpg
Copy link to clipboard
Copied
Ah, then having the layer selected is irrelevant then, as this is about using the visible groups and layers to set the save name.
Can you screenshot a couple of examples of the layer visibility on with corresponding filenames typed out so that the relationship is obvious.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Let me know if you need any more to explain it.
I tried to send the action file on this forum, but it doesn't allow me to attach the file type.
Copy link to clipboard
Copied
Try the following script. You will need to record it as an action step, replacing any Save As/Export - Save for Web (Legacy) steps in the action.
/*
Export Save for Web Named After Visible Top-Level Layers.jsx
v1.0 - 21st May 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/layer-name-used-to-save-file-with-action-or-script/m-p/14630542
Info: Action helper script used to replace an action save/export step to include a custom filename using the visible root/top-level layer names + doc name
*/
#target photoshop
try {
// Check that the file has been previously saved
app.activeDocument.path;
// Get the current doc
var doc = app.activeDocument;
// Get the doc path
var docPath = doc.path;
// Get the doc name without the extension
var docName = doc.name.replace(/\.[^\.]+$/, '');
// Get all of the root/top-level layers
var layers = doc.layers;
// Initialize strings to store the layer names
var visibleLayerGroups = '';
var visibleLayers = '';
// Loop over the layers
for (var i = 0; i < layers.length; i++) {
// Get the current layer
var layer = layers[i];
// Check if the layer is a group
if (layer.typename === 'LayerSet') {
// Check if the group is visible
if (layer.visible) {
// Append the group name to the string
visibleLayerGroups += layer.name;
/*
// Loop over the layers in the group
var groupLayers = layer.layers;
for (var j = 0; j < groupLayers.length; j++) {
var groupLayer = groupLayers[j];
// Check if the layer in the group is visible
if (groupLayer.visible) {
// Append the layer name to the string
visibleLayers += groupLayer.name + ' - ';
}
}
*/
}
} else {
// Check if the layer is visible
if (layer.visible) {
// Append the layer name to the string
visibleLayers += layer.name;
}
}
}
// Export the visible layer groups and layers
if (visibleLayerGroups !== "") {
var layerNames = visibleLayers + ' - ' + visibleLayerGroups;
var saveFileJPEG = new File(docPath + '/' + layerNames + ' - ' + docName + '.jpg');
SaveForWeb(saveFileJPEG);
} else {
alert('Attention: No layers are visible!');
}
} catch (e) {
alert('Error!' + '\r' + e + ', Line: ' + e.line);
}
// JPEG S4W Options
function SaveForWeb(saveFileJPEG) {
var sfwOptions = new ExportOptionsSaveForWeb();
sfwOptions.format = SaveDocumentType.JPEG;
sfwOptions.includeProfile = true;
sfwOptions.interlaced = 0;
sfwOptions.optimized = true;
sfwOptions.quality = 75;
app.activeDocument.exportDocument(saveFileJPEG, ExportType.SAVEFORWEB, sfwOptions);
}
Info on saving and running scripts here:
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html
Copy link to clipboard
Copied
I forgot to mention, that the other way to do this is to use Layer Comps, saving each comp with the name you require, then use the default Export Layer Comps to Files script.
https://helpx.adobe.com/au/photoshop/using/layer-comps.html
Copy link to clipboard
Copied
@AEL-13 - So how did things go?
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more