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

Add Tab Space to text

Explorer ,
Jan 27, 2016 Jan 27, 2016

Hi guys… I would like a Javascript to add tab space

to the selected text as shown on the image attached.

Could you please help me?

Many thanks in advance 🙂

pic.png

TOPICS
Scripting
884
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 , Jan 27, 2016 Jan 27, 2016

Hi W_J_T,

not bad. Perhaps this additions are also helpful for Puthoskey :

// tabulator_replaceSpaceWithTabulator.jsx

// required: a selected text frame

// https://forums.adobe.com/thread/2076401

function addTabs() {

    var doc = app.activeDocument;

    var txt = doc.selection[0];

   

    if (txt.typename == "TextFrame") {

        // useful complement, based on code IMHO written by Jongware

        tabInf = new Array(1);

        tabInf[0] = new TabStopInfo;

        // set here the tabulator po

...
Translate
Adobe
Mentor ,
Jan 27, 2016 Jan 27, 2016

\t = Tab

So on a basic level here is an example. It assumes you have a tab stop setup, otherwise you may have to add extra tabs '\t' for certain instances to get things evened out.


function addTabs() {

    var doc = app.activeDocument;

    var txt = doc.selection[0];

    if (txt.typename == "TextFrame") {

        curTxtString = txt.contents;

        curTxtString = curTxtString.replace('NAME:', 'NAME:\t').replace('ADDRESS:', 'ADDRESS:\t').replace('DATE:', 'DATE:\t').replace('PHONE:', 'PHONE:\t');

        txt.contents = curTxtString;

    }

}

addTabs();


Hope it helps your efforts.

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 ,
Jan 27, 2016 Jan 27, 2016

Hi W_J_T,

not bad. Perhaps this additions are also helpful for Puthoskey :

// tabulator_replaceSpaceWithTabulator.jsx

// required: a selected text frame

// https://forums.adobe.com/thread/2076401

function addTabs() {

    var doc = app.activeDocument;

    var txt = doc.selection[0];

   

    if (txt.typename == "TextFrame") {

        // useful complement, based on code IMHO written by Jongware

        tabInf = new Array(1);

        tabInf[0] = new TabStopInfo;

        // set here the tabulator position in pt/px

        tabInf[0].position = 55; 

        curTxtString = txt.contents;

        // curTxtString = curTxtString.replace('NAME:', 'NAME:\t').replace('ADDRESS:', 'ADDRESS:\t').replace('DATE:', 'DATE:\t').replace('PHONE:', 'PHONE:\t');

        // !!! Do not forget to replace the spaces too !!!

        curTxtString = curTxtString.replace('NAME: ', 'NAME:\t').replace('ADDRESS: ', 'ADDRESS:\t').replace('DATE: ', 'DATE:\t').replace('PHONE: ', 'PHONE:\t');

        txt.contents = curTxtString;

        for (i=0; i<txt.paragraphs.length; i++) {

            txt.paragraphs.tabStops = tabInf;

            }

        }

    }

addTabs();

Have fun

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 ,
Feb 01, 2016 Feb 01, 2016
LATEST

Many thanks guys.

It works like a charm

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