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

Delete white space and line numbering

Engaged ,
Sep 26, 2022 Sep 26, 2022

Copy link to clipboard

Copied

Greetings to all

I want a script that removes the white space at the beginning of each line

Number each line at the beginning of each line

 

 

Sample.jpg

 

I attached a psd file to the text to illustrate the idea

TOPICS
Actions and scripting , SDK

Views

55

Likes

Translate

Translate

Report

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 1 Correct answer

Community Expert , Sep 26, 2022 Sep 26, 2022

 

var s = activeDocument.activeLayer.textItem.contents.split('\r');
for (var i=0; i<s.length; i++) s[i] = s[i].replace(/^\s+/, i+1 + '/ ');
activeDocument.activeLayer.textItem.contents = s.join('\r');

 

Likes

Translate

Translate
Community Expert ,
Sep 26, 2022 Sep 26, 2022

Copy link to clipboard

Copied

 

var s = activeDocument.activeLayer.textItem.contents.split('\r');
for (var i=0; i<s.length; i++) s[i] = s[i].replace(/^\s+/, i+1 + '/ ');
activeDocument.activeLayer.textItem.contents = s.join('\r');

 

Likes

Translate

Translate

Report

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
Engaged ,
Sep 26, 2022 Sep 26, 2022

Copy link to clipboard

Copied

LATEST

@jazz-y 

Thank you very much for your interest and cooperation

Likes

Translate

Translate

Report

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