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

Unlock background layer by default and rename the layer

Community Beginner ,
Apr 04, 2024 Apr 04, 2024

Copy link to clipboard

Copied

Hi, I would like to know if someone has a script to verify if there is a "background" layer in a file, and if there is one, it will unlocks it and rename it to for example "default". I would like to integrate it into the Script Events Manager, but if I use the one that is by default in photoshop it renames to the filename (I am not savy in scipting, I have tried to use actions but if the opened file dont have a background but a regular layer it gives me an error).

Thank you in advance

TOPICS
Actions and scripting

Views

98

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 1 Correct answer

Community Expert , Apr 04, 2024 Apr 04, 2024

The standard script from Adobe (Presets/Scripts/Event Scripts Only/Open As Layer.jsx):

 

// (c) Copyright 2008.  Adobe Systems, Incorporated.  All rights reserved.

/*
@@@BUILDINFO@@@ Open As Layer.jsx 1.0.0.1
*/

var begDesc = "$$$/JavaScripts/OpenAsLayer/Description=Assign this to the open document event. This will promote a document with only a background layer to a layer with the document name." // endDesc
var begName = "$$$/JavaScripts/OpenAsLayer/MenuName=Open As Layer" // endName

// on l
...

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 04, 2024 Apr 04, 2024

Copy link to clipboard

Copied

LATEST

The standard script from Adobe (Presets/Scripts/Event Scripts Only/Open As Layer.jsx):

 

// (c) Copyright 2008.  Adobe Systems, Incorporated.  All rights reserved.

/*
@@@BUILDINFO@@@ Open As Layer.jsx 1.0.0.1
*/

var begDesc = "$$$/JavaScripts/OpenAsLayer/Description=Assign this to the open document event. This will promote a document with only a background layer to a layer with the document name." // endDesc
var begName = "$$$/JavaScripts/OpenAsLayer/MenuName=Open As Layer" // endName

// on localized builds we pull the $$$/Strings from a .dat file, see documentation for more details
$.localize = true;

try {

	if ( app.documents.length > 0 ) {
		var doc = activeDocument;
		if ( doc.layers.length == 1 && doc.activeLayer.isBackgroundLayer ) {
			doc.activeLayer.isBackgroundLayer = false;
			doc.activeLayer.name = doc.name;
		}
	}

} // try end

catch( e ) {
	// always wrap your script with try/catch blocks so you don't stop production
	// remove comments below to see error for debugging 
	// alert( e );
}

 

Change from:

 

doc.activeLayer.name = doc.name;

 

To:

 

doc.activeLayer.name = "default";

 

 

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