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

Batch adding line break behind every comma of text layer

Participant ,
Jul 21, 2024 Jul 21, 2024

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?

TOPICS
Actions and scripting , Windows
1.3K
Translate
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 2 Correct answers

Community Expert , Jul 21, 2024 Jul 21, 2024

Please provide a file.

 

You can copy a linebreak and paste it in the »Find and Replace Text« field. 

Screenshot 2024-07-22 at 08.21.29.pngScreenshot 2024-07-22 at 08.21.36.png

Translate
Community Expert , Jul 21, 2024 Jul 21, 2024

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
...
Translate
Adobe
Community Expert ,
Jul 21, 2024 Jul 21, 2024

Please provide a file.

 

You can copy a linebreak and paste it in the »Find and Replace Text« field. 

Screenshot 2024-07-22 at 08.21.29.pngScreenshot 2024-07-22 at 08.21.36.png

Translate
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
Community Expert ,
Jul 21, 2024 Jul 21, 2024
quote

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.

Translate
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
Participant ,
Jul 22, 2024 Jul 22, 2024

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?

Translate
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
Community Expert ,
Jul 22, 2024 Jul 22, 2024
LATEST
quote

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

Screenshot 2024-07-23 at 08.17.29.png

Translate
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
Community Expert ,
Jul 21, 2024 Jul 21, 2024

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);
        }
    }
}

 

 

Translate
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
Participant ,
Jul 22, 2024 Jul 22, 2024

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

Translate
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
Community Expert ,
Jul 22, 2024 Jul 22, 2024
quote

I am very grateful for your help ^^ However, the script not worked for me.


By @Zipser31550168t845

 

What does this mean exactly?

Translate
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
Community Expert ,
Jul 22, 2024 Jul 22, 2024

@Zipser31550168t845 

 

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):

 

2024-07-23_12-18-31 (1).png

 

And this is the result after running the script (the comma and space are replaced with a comma and return):

 

2024-07-23_12-18-37 (1).png

 

Can you provide a sample PSD file?

Translate
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
Participant ,
Jul 22, 2024 Jul 22, 2024

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!

Translate
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
Community Expert ,
Jul 22, 2024 Jul 22, 2024
quote

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.

Translate
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
Participant ,
Jul 22, 2024 Jul 22, 2024

thanks for your suggestion, I tested without group and it worked perfectly. I'll mark your first reply as correct answer

Translate
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
Community Expert ,
Jul 22, 2024 Jul 22, 2024
quote

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.

Translate
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