Script to Tag selected text and add attributes

Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Script to Tag selected text and add attributes

Viewing 3 reply threads
  • Author
    Posts
    • #95611

      Good day guys, need again your help. Is there anyone of you with a good heart who can help me on how to add TAG and ATTRIBUTES on selected text at the same time using a script in InDesign. (i.e., <emphasis type=”bold”>). Thank you. :)

    • #95615
      Loic Aigon
      Member

      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” );

    • #95625

      Many thanks Loic, your script works. You’re great!

    • #95626
      Loic Aigon
      Member

      Great.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.
>