Reply To: select some text in textframe and color this

#87028

Try this one and try to avoid all those try/catch things :)

var sel = app.selection[0];

// check your selection
if (sel != undefined) {
  var textHeaderTf = sel;
}

// the parent story
var parStory = textHeaderTf.parentStory;
// insert text at the end (realize, that there is no space before the new word)
parStory.insertionPoints[-1].contents = 'myNewText';

// a fill and a stroke color
var props = {
  fillColor: app.activeDocument.swatches[4],
  strokeColor: app.activeDocument.swatches[5]
}

// give the first word in the story a fill and a stroke color
var firstWord = parStory.words[0];

// since you insert something above, therre is always a word
firstWord.properties = props;

// give the frame a fill and a stroke color
textHeaderTf.properties = props;

This article was last modified on August 2, 2016

Comments (0)

Loading comments...