• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Save Active Layer Name As File

Contributor ,
Sep 18, 2020 Sep 18, 2020

Copy link to clipboard

Copied

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 🙂

 

 

TOPICS
Actions and scripting

Views

4.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 3 Correct answers

Community Expert , Jan 22, 2024 Jan 22, 2024
quote

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?

 


By @Jenny Rhea


Yes, hav

...

Votes

Translate

Translate
New Here , Feb 14, 2024 Feb 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

 

Votes

Translate

Translate
New Here , Feb 14, 2024 Feb 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

...

Votes

Translate

Translate
Adobe
Community Beginner ,
Sep 18, 2020 Sep 18, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

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

Capture d’écran 2020-09-19 à 10.28.46.png

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

Capture d’écran 2020-09-19 à 10.29.05.png

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

Hello sir, I couldn't understand the language in the images which are you posted, can you please change the Photoshop's language to English and repost the images?

Thankyou sir.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

No I cannot. Sorry

Here is the way to do that :

Select the layer

  1. Click on the eye icon for that layer in the layers panel with Alt key pressed. it will hide all other layers
  2. Then menu > File Export > Export layers as files
  3. Then check Only visible in the dialog box.
  4. Leave empty the prefix
  5. It will save the layer as a file. It will also put a prefix number… (This is to prevent overriding of layers having the same name). If you do not want this number you will have to change a few instructions in the Export Layers To Files.jsx file in the scripts folder. I did it so it works. I can put that file on Gdrive if someone want it…
  6. All this can be recorded as an action then you will just have to select the layer to export and launch the action…

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

This is the way I use to save one layer as a jpg/png file.

Right click on the layer

Export As

Export layer.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

// 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 );
	};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

Then the is the file name problem 

image.png

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

Good point! 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

There is also the duplicate name problem layer names do not need to be unique many document  will have layers with identical layer names like Background. That is why scripts like export layers the files include doc name and layer stack level in new file names.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

I stole a regular expression from Export Layers for file names for you a layer name invalid characters

~!@#$%^&*()_+`-={}|[]\:";'<>?,./1234567890

will become file name

~!@#$%^&_()_+`-={}_[]__”;’___,._1234567890

// 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.replace(/[:\/\\*\?\"\<\>\|]/g, "_");  // '/\:*?"<>|' -> '_' // from export layers to files
// 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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

Maybe this answer from Julia would help:

https://community.adobe.com/t5/photoshop/ps-cc-export-layer-to-files-without-prefix-numbers/m-p/6048...

Personnaly I choosed to adress the situation by modifying the "Export Layers as file" Photoshop JSX script in order to get rid of suffixes and then use an action script simply refering to the menu item… It is a one click solution for the end user. You select the layer and click to launch the action, and that's it.

But all other ways are interesting, specially writing a dedicated JSX script as you did. I will check it, Bravo!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

First of all thank you to all who have looked at this. So far this one works excellent.

 

One final question if I may:

 

Pretend I would like to save the .jpeg file to

C:\MyFolder

 

 How will I do it?

 

// 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 );
	};

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

Change the path you could make that selectable with  a select folder dialog

var thePath = "~/Desktop"

you should also add the regular expression to the layer name

var theName = myDocument.activeLayer.name.replace(/[:\/\\*\?\"\<\>\|]/g, "_");  // '/\:*?"<>|' -> '_' // from export layers to files

  

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

// 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 thePath = Folder.selectDialog("Choose a folder", thePath);
var theName = myDocument.activeLayer.name.replace(/[:\/\\*\?\"\<\>\|]/g, "_");  // '/\:*?"<>|' -> '_' // from export layers to files
// 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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

Thank you, the save-as dialog option is excellent too, it will come in handy 🙂

 

But I still need to save file directly to C:\MyFolder with no dialog. 

 

I have changed this:

var thePath = "~/Desktop"

to this:

var thePath = "C/MyFolder"

 

but it still does not work. what am I doing wrong? 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

try

var thePath = "/c/MyFolder"

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

unfortunately no, it is still saving image into original folder that the document was loaded from

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 19, 2020 Sep 19, 2020

Copy link to clipboard

Copied

Update - 

 

this works:

 

1. create new document in photoshop

2. create new layer

3. draw/scribble anything on layer

 

when the script runs, it successfully saves the file to C:\MyFolder

 

 

BUT- this doesn't work:

 

1. load an existing .psd file from anywhere on your hard drive

2. create a new layer

3. draw/scribble anyhting on layer

 

Now when script runs, it does not save to C:\MyFolder, but instead it saves it to original .psd location on hard drive.

 

How do we do so that it *always* saves to C:\MyFolder no matter if it is new photoshop document or existing one loaded from hard drive?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2020 Sep 20, 2020

Copy link to clipboard

Copied

It the top code the us set thepath

 

you need to override that like I did with the select code

 

 

try {
var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
}

 or remove it 

 

 

This only run if the document is new has pot path

catch (e) {
var theName = myDocument.name;
var thePath = "~/Desktop"
};

 

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 20, 2020 Sep 20, 2020

Copy link to clipboard

Copied

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 );
	};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Sep 20, 2020 Sep 20, 2020

Copy link to clipboard

Copied

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.
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

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,

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines