Copy link to clipboard
Copied
I've complete some psd files which contained a lot of text layers, but I forgot to separate them into lines ( they must be broken at each comma & dot).
For example:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit"
The result must be
"Lorem ipsum dolor sit amet,
consectetur adipiscing elit"
Tried with Find and replace tool but I don't know which line break symbol is.
Does anyone have any idea to help me?
Please provide a file.
You can copy a linebreak and paste it in the »Find and Replace Text« field.
If only Photoshop was InDesign when it came to text!
I don't know if this is possible using the standard Edit > Find and Replace Text... command.
It is possible to script using a regular expression based find/replace, however, if you have different text attributes (sizes, colours etc) then the following code may not work correctly (this script changes all text layers from comma+space to comma+return):
/*
Text Replace Comma Space for Comma Return in All Text Layers and Groups.jsx
v1.0 - 25t...
Copy link to clipboard
Copied
Please provide a file.
You can copy a linebreak and paste it in the »Find and Replace Text« field.
Copy link to clipboard
Copied
You can copy a linebreak and paste it in the »Find and Replace Text« field.
By @c.pfaffenbichler
I didn't know that!
EDIT: I just tried and this works beautifully! I copied the return character from within the text inside Photoshop.
Copy link to clipboard
Copied
thanks for your opinion but maybe it's not work with mine, I tried with many random paragraphs but nothing can be copied and pasted (or might I copied a different character to you?)
Could you give me that character?
Copy link to clipboard
Copied
thanks for your opinion but maybe it's not work with mine, I tried with many random paragraphs but nothing can be copied and pasted (or might I copied a different character to you?)
Could you give me that character?
By @Zipser31550168t845
Copy link to clipboard
Copied
If only Photoshop was InDesign when it came to text!
I don't know if this is possible using the standard Edit > Find and Replace Text... command.
It is possible to script using a regular expression based find/replace, however, if you have different text attributes (sizes, colours etc) then the following code may not work correctly (this script changes all text layers from comma+space to comma+return):
/*
Text Replace Comma Space for Comma Return 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(/\, /g, ',\r');
}
}
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);
}
}
}
Copy link to clipboard
Copied
I am very grateful for your help ^^ However, the script not worked to me. Yeah, working with Photoshop is a bit annoyed when they limit many things, I wished I could have more option than it
Copy link to clipboard
Copied
I am very grateful for your help ^^ However, the script not worked for me.
By @Zipser31550168t845
What does this mean exactly?
Copy link to clipboard
Copied
You marked my reply as a correct answer, however I have unmarked it as it isn't. :]
This is what I have before running the script (a comma followed by a space):
And this is the result after running the script (the comma and space are replaced with a comma and return):
Can you provide a sample PSD file?
Copy link to clipboard
Copied
oops, I've left a reply to you but it has disapeared when I submitted XD I'm terribly sorry about my forgetfulness that not telling you the text layers are inside a group! That's why the script not worked, not its fault!
Copy link to clipboard
Copied
oops, I've left a reply to you but it has disapeared when I submitted XD I'm terribly sorry about my forgetfulness that not telling you the text layers are inside a group! That's why the script not worked, not its fault!
By @Zipser31550168t845
Yes, that sort of information is critical for scripting.
For testing with the current code, can you ungroup in a copy of the original file? If the script works for you I can add code to process text layers inside groups.
The suggestion from @c.pfaffenbichler works within groups, all you need to do is copy the comma and return from within a text layer and then paste it into the replace field.
Copy link to clipboard
Copied
thanks for your suggestion, I tested without group and it worked perfectly. I'll mark your first reply as correct answer
Copy link to clipboard
Copied
thanks for your suggestion, I tested without group and it worked perfectly. I'll mark your first reply as correct answer
By @Zipser31550168t845
Thank you, I will come back later and update the previous the code to process layers or layers in groups when I have time.
I have also marked the reply from @c.pfaffenbichler as a correct reply as this works too using the native find/replace text feature.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more