Script to Tag selected text and add attributes
- This topic has 3 replies, 2 voices, and was last updated 6 years, 10 months ago by .
- You must be logged in to reply to this topic.
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / 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
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. :)
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” );
Many thanks Loic, your script works. You’re great!
Great.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies allows us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
To provide the best experiences, we and our partners use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us and our partners to process personal data such as browsing behavior or unique IDs on this site and show (non-) personalized ads. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Click below to consent to the above or make granular choices. Your choices will be applied to this site only. You can change your settings at any time, including withdrawing your consent, by using the toggles on the Cookie Policy, or by clicking on the manage consent button at the bottom of the screen.
You have to be logged in to save.
Not a member? Join Today - it's FREE!