Copy link to clipboard
Copied
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 🙂
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
Copy link to clipboard
Copied
\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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Many thanks guys.
It works like a charm
Find more inspiration, events, and resources on the new Adobe Community
Explore Now