/*
Utility Pack Scripts created by David M. Converse ©2018-24
This script renames text layers in an open Photoshop document
Last modifed 7/5/2024
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#target photoshop
renameTextLayers();
function renameTextLayers(){
if(!app.documents.length > 0){
return;
}
var docRef = null;
var vis = true;
var LayerRef = null;
var TextRef = null;
var layerText = '';
try{
docRef = app.activeDocument;
docRef.activeLayer = docRef.artLayers[0];
for(var i = 0; i < docRef.artLayers.length; i++){
LayerRef = docRef.artLayers[i];
vis = true;
if(LayerRef.kind == LayerKind.TEXT){
if(!LayerRef.visible){
vis = false;
}
TextRef = LayerRef.textItem;
layerText = TextRef.contents;
layerText = layerText.replace(/\r$/, '');
layerText = layerText.replace(/,\r/, ', ');
if(layerText.search('\r') == -1){
layerText = layerText.split(' ');
layerText[0] = layerText[0].replace(',', '');
}
else{
layerText = layerText.split('\r');
}
LayerRef.name = layerText[0];
if(vis == false){
LayerRef.visible = false;
}
}
}
}
catch(e){
Window.alert(e + e.line);
}
}
... View more