Skip to main content
Participating Frequently
Mar 28, 2024 9:58 PM UTC
Answered

I want to save as jpg with the same name as the selected layer.

Hi all,

 

I want to save as jpg with the same name as the selected layer.

The process is like this. I need to manually select a layer then run a script/action/whatever to save the image file with jpeg quality 12 in the same folder as the PSD file. The name of the file should be the same as the layer name I have manually selected.

 

Thanks in advance!

This topic is closed to new replies. Start a new post to keep the conversation going.
Stephen Marsh
Stephen MarshCorrect answer
Community Expert
Mar 28, 2024 11:22 PM UTC

This is working like a charm Stephen! Thank you so much! Where could I add the name of the main file as a prefix? So if the main file with all the layers is called "MainPants.psd" and I run the script then I should get MainPants37.jpg (so without the extension PSD). Thanks again!


I have updated the original code to a new 1.1 version.

 

As per your example, there is no space between the docName and layerName:

 

var jpgSave = new File(docPath + "/" + docName + "" + layerName + ".jpg");

 

I have left a placeholder there to add a space or another separator character if needed, in the example below an _ underscore character:

 

var jpgSave = new File(docPath + "/" + docName + "_" + layerName + ".jpg");

 

11 replies

Stephen Marsh
Community Expert
Community Expert
Mar 28, 2024 10:21 PM UTC

@Dusan331314882hci 

 

I presume that you need to toggle off the visibility of all other layers, so that only the active layer content is saved as a JPEG? Then set the layer visibility back to how it was beforehand...

Translate
Participating Frequently
Mar 28, 2024 10:25 PM UTC

I need to turn on the visibility of that layer, save the file with the name of that selected layer.

Then turn manually some layers off and some other layers on. Then select again a layer to get the file name for the save and so on.

Translate
Spas K.
Community Expert
Community Expert
Mar 28, 2024 10:31 PM UTC

You can use Generate Assets perhaps? Although it doesn't save in the same folder, but in a sub-folder named assets-filename.

Translate