Reply To: Script to Tag selected text and add attributes

#95615
Anonymous
Inactive

var main = function(paragraph) {
var doc = app.properties.activeDocument,
text,
xt,
xe,
xa;

if ( !doc ) return;

xt = doc.xmlTags.itemByName (“emphasis”);
!xt.isValid && xt = doc.xmlTags.add ({name:”emphasis”});
text = app.selection;
if ( text.length!=1
|| (!text[0].properties.baseline)
) {
alert(“You need to select some text…”);
return;
}
text = text[0];

xe = doc.xmlElements[0].xmlElements.add(xt, text);
xa = xe.xmlAttributes.itemByName (“type”);
!xa.isValid && xa = xe.xmlAttributes.add( “type”, “bold” );}

var u;

app.doScript ( “main(app.activeDocument.stories[0].paragraphs[-1])”,u,u,UndoModes.ENTIRE_SCRIPT, “The Script” );

This article was last modified on June 22, 2017

Comments (0)

Loading comments...