Skip to main content
Inspiring
September 19, 2020
Answered

Save Active Layer Name As File

  • September 19, 2020
  • 8 replies
  • 6760 views

Good evening, everyone.

 

Is there a way to save the active layer in a photoshop document as a .jpeg?

 

In other words, I would like to:

 

1. save the current(active) layer as a .jpeg

2. use the active layer name as the file name

3. assign the save path in the script (for example, "/g/MyFolder")

 

I have few scripts which are close to this but not quite.

 

Thank you in advance 🙂

 

 

This topic has been closed for replies.
Correct answer Hazel35450925m18c

The user is asking how to save a file in Adobe software using the name of the currently active layer. There are two main methods mentioned:

1. **Using the "Export Layers to Files" option:**
- Hide all other layers except the active one.
- Go to File > Export > Export Layers to Files.
- Check the "Only visible" box and leave the prefix empty.
- This will save the active layer as a separate file with its name.

2. **Using a script:**
- Code snippets are provided in the thread that automate the process of getting the active layer name and saving the file with that name. This method requires some scripting knowledge.

Overall, the user is looking for a way to streamline their workflow by automatically using the layer name as the file name when saving.

8 replies

Davide_Barranca12040269
Community Expert
April 11, 2024

Answers have already been given; I just wanted to point out that you can now drag a layer, say, directly to the Desktop (or any other folder in the File Explorer / macOS Finder) to simulate the Quick Export as PNG.

 

Davide Barranca - PS developer and authorwww.ps-scripting.com
Brainiac
April 11, 2024

With one caveat, this doesn't work if Legacy Export As is enabled.

Hazel35450925m18cCorrect answer
New Participant
February 14, 2024

The user is asking how to save a file in Adobe software using the name of the currently active layer. There are two main methods mentioned:

1. **Using the "Export Layers to Files" option:**
- Hide all other layers except the active one.
- Go to File > Export > Export Layers to Files.
- Check the "Only visible" box and leave the prefix empty.
- This will save the active layer as a separate file with its name.

2. **Using a script:**
- Code snippets are provided in the thread that automate the process of getting the active layer name and saving the file with that name. This method requires some scripting knowledge.

Overall, the user is looking for a way to streamline their workflow by automatically using the layer name as the file name when saving.

focused_Essence0D44
New Participant
April 8, 2024

Hello,

Thank you for your answer It saved me so much time but I am having another issue.. 

I was wondering if there is any way to add my layer name to my file name and save it.

Like; my file name is OBJ and my layer name is redcarpet so when I export it the final jpg name would be OBJ_redcarpet. 

Brainiac
April 8, 2024

You would need to modify whichever script you are using to either save with app.activeDocument.name tacked on or rename the file once saved to disk.

New Participant
February 14, 2024

(It is insane that Adobe doesn't monitor this community to supply direct solutions to questions like this). @gangeek  you can use the built-in feature called "Image Assets" under the File > Generate menu in Photoshop. Here is more about the feature, including the ability to export files to specific directories: https://helpx.adobe.com/photoshop/using/generate-assets-layers.html

 

New Participant
January 22, 2024

I have composites built with individual pictures I want saved out as the layer name.  So a background will show up behind each layer of a kids photo.... Is there a way to save the shown layer as a file, or even to automate the process so that layer saves, turns off the layer, turns on the next layer, saves as that layer name, turns off the layer, turns on the next layer,.....  But the background won't change and other layers won't change either.  Does that make sense?

 

c.pfaffenbichler
Community Expert
January 22, 2024

It might make sense to post meaningful screenshots (including all pertinent Panels) to clarify. 

gangeekAuthor
Inspiring
September 20, 2020

Success!

 

Thanks you to both JJMack and c.pfaffenbichler, you both contribute to the forums are most helpful and invaluable, each and every time. 

 

Here is final code which will save current layer to jpeg in specified folder:

 

// save jpg of active layer;
// 2020, use it at your own risk;
if (app.documents.length > 0) {
var myDocument = app.activeDocument;

var theName = myDocument.name;
var thePath = "/c/MyFolder"
 
var theName = myDocument.activeLayer.name;
// duplicate;
var myDocument = app.activeDocument.duplicate("theCopy", false);
hideOthers ();
// jpg options;
var jpgopts = new JPEGSaveOptions();
jpgopts.embedProfile = true;
jpgopts.formatOptions = FormatOptions.STANDARDBASELINE;
jpgopts.matte = MatteType.NONE;
jpgopts.quality = 10;
myDocument.saveAs((new File(thePath+"/"+theName+".jpg")),jpgopts,true);
// close;
myDocument.close(SaveOptions.DONOTSAVECHANGES);
};
////// hide others //////
function hideOthers () {
	// =======================================================
	var idShw = charIDToTypeID( "Shw " );
		var desc2 = new ActionDescriptor();
		var idnull = charIDToTypeID( "null" );
			var list1 = new ActionList();
				var ref1 = new ActionReference();
				var idLyr = charIDToTypeID( "Lyr " );
				var idOrdn = charIDToTypeID( "Ordn" );
				var idTrgt = charIDToTypeID( "Trgt" );
				ref1.putEnumerated( idLyr, idOrdn, idTrgt );
			list1.putReference( ref1 );
		desc2.putList( idnull, list1 );
		var idTglO = charIDToTypeID( "TglO" );
		desc2.putBoolean( idTglO, true );
	executeAction( idShw, desc2, DialogModes.NO );
	};
Brainiac
September 20, 2020
Why don't you just duplicate the active layer into a new document?

Comment. The toggleOthers visible command is very tricky.
If you accidentally made it for a layer by hand, then in the script your same command can produce a completely opposite effect.
 
gangeekAuthor
Inspiring
September 22, 2020

thanks r-bin, so far is working perfectly. I have not yet come across any problems but I will reply here if trouble occurs with the script.  🙂

 

Regards,

 

 

c.pfaffenbichler
Community Expert
September 19, 2020
// save jpg of active layer;
// 2020, use it at your own risk;
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
try {
var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
}
catch (e) {
var theName = myDocument.name;
var thePath = "~/Desktop"
};
var theName = myDocument.activeLayer.name;
// duplicate;
var myDocument = app.activeDocument.duplicate("theCopy", false);
hideOthers ();
// jpg options;
var jpgopts = new JPEGSaveOptions();
jpgopts.embedProfile = true;
jpgopts.formatOptions = FormatOptions.STANDARDBASELINE;
jpgopts.matte = MatteType.NONE;
jpgopts.quality = 10;
myDocument.saveAs((new File(thePath+"/"+theName+".jpg")),jpgopts,true);
// close;
myDocument.close(SaveOptions.DONOTSAVECHANGES);
};
////// hide others //////
function hideOthers () {
	// =======================================================
	var idShw = charIDToTypeID( "Shw " );
		var desc2 = new ActionDescriptor();
		var idnull = charIDToTypeID( "null" );
			var list1 = new ActionList();
				var ref1 = new ActionReference();
				var idLyr = charIDToTypeID( "Lyr " );
				var idOrdn = charIDToTypeID( "Ordn" );
				var idTrgt = charIDToTypeID( "Trgt" );
				ref1.putEnumerated( idLyr, idOrdn, idTrgt );
			list1.putReference( ref1 );
		desc2.putList( idnull, list1 );
		var idTglO = charIDToTypeID( "TglO" );
		desc2.putBoolean( idTglO, true );
	executeAction( idShw, desc2, DialogModes.NO );
	};
JJMack
Community Expert
September 19, 2020

Then the is the file name problem 

JJMack
c.pfaffenbichler
Community Expert
September 19, 2020

Good point! 

The layer’s name could indeed defie the requirements, so one might have to insert checks to remove the offending parts. 

JJMack
Community Expert
September 19, 2020

There is a basic problem with your what you want to do.  A layer can contain transparency and be larger or smaller then the document canvas size. Jpeg file format does not support transparency only has support for a background layer. That will crop the layer to canvas size fill empty area with background colored pixels and blend in color into transparent areas.

JJMack
pixelplanetoffl
New Participant
September 19, 2020

Hello my dear creator,

You want to save the active layer as a .jpeg file right? First of all select the layer you want to save it as a seperate file then right click on the layer > Export as 

Select the format and click the Export button.

I hope this will helps you.

Thank you my dear creator.

gangeekAuthor
Inspiring
September 19, 2020

OK, well, it is excellent! I had never known about this way to save a layer to a file - thank you for posting this 🙂

 

However,  I was wondering if there is a way to do it with scripting. I have several scripts which will save current layer to file but none of them are quite what I am after. 

 

I am hoping to just run script, and it will automatically save current layer to file (.jpeg) with layer name as filename and also dictate (in the script) the path in which file will be saved to. 

didiermazier
Community Expert
September 19, 2020

In this case you could create an action script based on export layers as files (sorry french UI) 

  • You only would have to hide all layers except the one to export
  • and then check only visible layers in the export dialog box

And if you do not specify a prefix (just keep it empty) the file will have the layer name