Answered
Pls help) changing text layers to one line text photoshop script
Hi!
I'm searching for the script that makes all text layers to one line text like below @ @
Is it possible this function working on phoshop?

Hi!
I'm searching for the script that makes all text layers to one line text like below @ @
Is it possible this function working on phoshop?

Presuming that "hard" paragraph returns are used, not shift "soft" returns:
/*
Text Replace in All Text Layers and Groups.jsx
v1.0 - 25th July 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/batch-adding-line-break-behind-every-comma-of-text-layer/m-p/14753971
*/
#target photoshop
if (app.documents.length > 0) {
var doc = app.activeDocument;
processLayersAndGroups(doc.layers);
} else {
alert("A document must be open to run this script!");
}
function changeTextContents(layer) {
// Check if the layer is a text layer
if (layer.kind == LayerKind.TEXT) {
// Regular expression to change comma+space to comma+return
layer.textItem.contents = layer.textItem.contents.replace(/\r/g, '');
}
}
function processLayersAndGroups(layers) {
// Recursively process the root/top-level layers
for (var i = 0; i < layers.length; i++) {
var layer = layers[i];
if (layer.typename == "ArtLayer") {
changeTextContents(layer);
// Recursively process the layers within all groups
} else if (layer.typename == "LayerSet") {
processLayersAndGroups(layer.layers);
}
}
}
Or:
/*
Utility PS Scripts created by David M. Converse ©2018-21
This script is a demo of replacing text
Last modified 6/2/2021
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
layerUpdate();
function layerUpdate(){
if(documents.length > 0){
var originalDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.ERROR;
var originalRulerUnits = preferences.rulerUnits;
try{
var docRef = activeDocument;
preferences.rulerUnits = Units.POINTS;
for(var i = 0; i < docRef.artLayers.length; i++){
var LayerRef = docRef.artLayers[i];
if(LayerRef.kind == LayerKind.TEXT){
var TextRef = LayerRef.textItem;
var layerText = TextRef.contents;
var newText = layerText.replace(/\r/g, '');
TextRef.contents= newText;
}
}
preferences.rulerUnits = originalRulerUnits;
app.displayDialogs = originalDialogMode;
}
catch(e){
}
}
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.