0
JS:CS3 Newbie needs help! find/change character styles
New Here
,
/t5/indesign-discussions/js-cs3-newbie-needs-help-find-change-character-styles/td-p/1148415
Apr 04, 2008
Apr 04, 2008
Copy link to clipboard
Copied
I'm new to scripting and JavaScript is giving me a headache, but I'll keep trying. What I'm trying to do is automate a few things so that the production time of our school newspaper is reduced while insuring accuracy.
I've played around a little with the text find change sample and the changing or adding paragraph styles in the InDesignCS3_ScriptingGuide_JS.pdf and I barely understand what I'm doing.
When us page designers receive text to place in the document, our editors mark the text with tags like: < b >text< / b >, where the word "text" is to be bolded. (there wouldn't any spaces between < and b and > etc. I just did that so It'll show up here). We have basic character styles and paragraph styles set up, and we just started working with nested styles.
Is there a way we can search for the < b > tag and bold everything after it up until the < / b > tag? Sort of the way it does for html (the way it would do for this message if I took out the spaces). It'll be great if it could remove the tags as well, but if not, I know I could create a find/change script to do the removal afterwards.
I appreciate any input.
Thanks!
I've played around a little with the text find change sample and the changing or adding paragraph styles in the InDesignCS3_ScriptingGuide_JS.pdf and I barely understand what I'm doing.
When us page designers receive text to place in the document, our editors mark the text with tags like: < b >text< / b >, where the word "text" is to be bolded. (there wouldn't any spaces between < and b and > etc. I just did that so It'll show up here). We have basic character styles and paragraph styles set up, and we just started working with nested styles.
Is there a way we can search for the < b > tag and bold everything after it up until the < / b > tag? Sort of the way it does for html (the way it would do for this message if I took out the spaces). It'll be great if it could remove the tags as well, but if not, I know I could create a find/change script to do the removal afterwards.
I appreciate any input.
Thanks!
TOPICS
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/js-cs3-newbie-needs-help-find-change-character-styles/m-p/1148416#M339203
Apr 05, 2008
Apr 05, 2008
Copy link to clipboard
Copied
You've not found yourself the easiest of tasks! You need GREP find/replace, not text. Do you have any experience with GREP? It's worth investigating, it's a powerful feature. The script below handles bold. For clarity, it doesn't do any error checking: it assumes that there's a document with text in it and that the document contains a character style called 'bold'.
// talk to Indesign, nobody else
#target indesign
// reset the Find/Change dialog
app.findGrepPreferences = app.changeGrepPreferences = null;
// find everything between <b> and (including these codes)
app.findGrepPreferences.findWhat = '<b>.+?</b>';
// add 'bold' style
app.changeGrepPreferences.appliedCharacterStyle = 'bold';
// make the changes
app.activeDocument.changeGrep();
// now delete the <b> and </b> codes
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = '</?b>';
app.changeGrep();
You can adapt it easily to handle other codes, and at a later stage you could generalise it so that you needn't repeat whole bunches of code.
Good luck with your first forays. Again, it's not the easiest of tasks, but it's worth getting to grips with.
Peter
// talk to Indesign, nobody else
#target indesign
// reset the Find/Change dialog
app.findGrepPreferences = app.changeGrepPreferences = null;
// find everything between <b> and (including these codes)
app.findGrepPreferences.findWhat = '<b>.+?</b>';
// add 'bold' style
app.changeGrepPreferences.appliedCharacterStyle = 'bold';
// make the changes
app.activeDocument.changeGrep();
// now delete the <b> and </b> codes
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = '</?b>';
app.changeGrep();
You can adapt it easily to handle other codes, and at a later stage you could generalise it so that you needn't repeat whole bunches of code.
Good luck with your first forays. Again, it's not the easiest of tasks, but it's worth getting to grips with.
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Dave_Bubbins_
AUTHOR
New Here
,
LATEST
/t5/indesign-discussions/js-cs3-newbie-needs-help-find-change-character-styles/m-p/1148417#M339204
Apr 05, 2008
Apr 05, 2008
Copy link to clipboard
Copied
Thanks Peter, this is exactly what I was looking to do. I know of GREP but the InDesignCS3 Scripting Guide wasn't much help to me. I know a little HTML but this stuff is a lot more complicated. JavaScript books seem more web based and not get in to Indesign specifics.
I took your code and altered it to look for i tags instead of the b tags to find and apply an italics style. It works like a charm.
Thanks again.
I took your code and altered it to look for i tags instead of the b tags to find and apply an italics style. It works like a charm.
Thanks again.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

