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

Insert tab after the number(up to 2 digits) Script

Explorer ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

I would like to create a script that will simply adds tabs after the (number and the period). I was trying the ChainGrep, but cant find a way to execute it. I tried using find and replace as one of the ChainGrep: 

FIND: \d. REPLACE: \d.\t but it simply replace the number as "\d.\t" converted to chracters. Is there any way to execute this? Thanks in advance. 

Screen Shot 2021-04-27 at 9.01.03 AM.png

TOPICS
How to , Scripting , SDK , Type

Views

1.2K

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 , Apr 27, 2021 Apr 27, 2021

Did you try:

FIND: (\d+\.)\s

CHANGE: $0\t

 

Better yet, why not strip the manual numbering out in favor of a numbered Paragraph Style?

 

Votes

Translate

Translate
Community Expert ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

When you execute your changes, change a paragraph style to the one with proper tab alignment set. Then in your changeGrep properties: 

{changeTo: "$0\\t~i", appliedParagraphStyle: "aCleanStyle"}

Votes

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
Community Expert ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Hi @brianp311 

For reasons I don't understand, the OP definitely doesn't want to use paragraph formats at all.

Votes

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
Community Expert ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Well, they are going to be in for a sad surpise when they realize they can't change tab stops in changeGrepPreferences.

Votes

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
Explorer ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

yes it is, but i have set some paragraph style to execute those functions, however Im still looking for a possible way to put the tabstop function on my script

Votes

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
Community Expert ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

The javascript you are showing is a different animal to the chain of GREP searches. You cannot mix the two.

Mike Witherell

Votes

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
Explorer ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Thanks mike, I think I'll stick to the first process you've mention. 

Votes

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
Guide ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

// by FRIdNGE, Michel Allio [29/04/2021]

var myDoc = app.activeDocument;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "(?s)^\\d+\\.\\K\\h+";
app.changeGrepPreferences.changeTo = "\\t";
myFound = myDoc.findGrep();
var F = myFound.length,  f ;
for ( f = 0; f < F ; f++ ) {
    if ( !myFound[f].tabStops[0].isValid ) myFound[f].tabStops.add({position: "0.125 in"});
    else myFound[f].tabStops[0].position = "0.125 in";
    myFound[f].tabStops[0].alignment = TabStopAlignment.LEFT_ALIGN;
}
myDoc.changeGrep();
app.findGrepPreferences = app.changeGrepPreferences = null;

 

(^/)

Votes

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
Explorer ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

LATEST

Hi @Mike Witherell I just want to ask, is there a way that I can eliminate single spaces between texts? I have a file that contains "mL/ml" values and I want to remove the spaces between them.

eg: 3 mL to 3mL

 

I want to include this on the script I am building. Thank you in advance

Votes

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