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

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

Explorer ,
Apr 27, 2021 Apr 27, 2021

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
2.6K
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 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?

 

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

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"}

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

Hi @brian_p_dts 

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

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

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

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

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

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

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

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

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

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

 

(^/)

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

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