Copy link to clipboard
Copied
I have been searching for a script to open an image and rename a background layer into the file name. I found the below script which works perfectly; however, I'd like to have the layer name without a file extension.
Can someone please help me with editing the script?
Your help will be much appreciated.
// (c) Copyright 2008. Adobe Systems, Incorporated. All rights reserved.
/*
@@@BUILDINFO@@@ OpenAsLayer.jsx 1.0.0.0
*/
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
// on localized builds we pull the $$$/Strings from a .dat file, see documentation for more details
$.localize = true;
if ( app.documents.length > 0 ) {
var doc = activeDocument;
if ( doc.layers.length == 1 && doc.activeLayer.isBackgroundLayer ) {
doc.activeLayer.isBackgroundLayer = false;
var docNameNoExtension = doc.name;
if (stripExtension) {
var extensionIndex = docNameNoExtension.lastIndexOf (".");
if (extensionIndex != -1) {
docNameNoExtension = docNameNoExtension.substr(0, extensionIndex);
}
}
doc.activeLayer.name = docNameNoExtension;
}
}
Modified code (not exhaustively tested, use at your own risk):
// (c) Copyright 2008. Adobe Systems, Incorporated. All rights reserved.
/*
@@@BUILDINFO@@@ OpenAsLayer.jsx 1.0.0.0
*/
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
// on localized builds we pull the $$$/Strings from a .dat file, see documentation for more details
$.localize = tr...
Copy link to clipboard
Copied
Modified code (not exhaustively tested, use at your own risk):
// (c) Copyright 2008. Adobe Systems, Incorporated. All rights reserved.
/*
@@@BUILDINFO@@@ OpenAsLayer.jsx 1.0.0.0
*/
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
// on localized builds we pull the $$$/Strings from a .dat file, see documentation for more details
$.localize = true;
if (app.documents.length > 0) {
var doc = activeDocument;
if (doc.layers.length == 1 && doc.activeLayer.isBackgroundLayer) {
doc.activeLayer.isBackgroundLayer = false;
var docNameNoExtension = doc.name.replace(/\.[^\.]+$/, '');
}
}
doc.activeLayer.name = docNameNoExtension;
The script is intended to be driven via the File > Scripts > Scripts Events Manager:
https://prepression.blogspot.com/2021/10/photoshop-script-events-manager.html
It could be run manually though. Example location of the original script (backup before replacing):
Mac:
/Applications/Adobe Photoshop 2022/Presets/Scripts/Event Scripts Only/Open As Layer.jsx
Win:
C:\Program Files\Adobe\Adobe Photoshop 2022\Presets\Scripts\Event Scripts Only\Open As Layer.jsx
Copy link to clipboard
Copied
Amazing!! It works perfectly!
Thank you so much for your time and great support. Truly appreciated!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more