I work for a daily newspaper and I am fairly new to the world of InDesign javascripting. I have been making the most of modifying FindChangesByList.jsx and the support file FindChangeList.txt to format articles and sports agate. I am using InDesign CS5.
I have a couple of questions and would appreciate any assistance:
1. AppliedParagraphStyle question
How do you refer to a paragraph style when it is in a Style Group folder?
2. Grep question
A. I am trying to get FindChangeList to look for a reporter's name, which is at the beginning of the article and is two upper case words followed by a comma.
I've tried the following - grep {findWhat:"\u+ \u+[,]"} - but it doesn't seem to work.
B. Once I find the reporter's name, I would like to add the word "By" in front of the name and remove the comma. I am at a lose how to do this.
3. I am also looking for a way to find a reporter's name (which is at the beginning of the article) and then add that reporter's contact information at the end of the article. I am not sure this can be done with FindChangeByList.
4. Last question: What book or guide would you commend for someone just learning javascripting in InDesign?
Thanks in advance.
I'm not a javascripter, but I can answer most of your questions....
1. There isn't an example in the sample text file, but someone posted the answer in a thread that came up as related to this one. This is how you'd do it for a para style called "Blue" in a style group called "Colors":
appliedParagraphStyle:app.activeDocument.paragraphStyleGroups.item("Co lors").paragraphStyles.item("Blue")
2A/B. You're close, but whenever you have something in GREP that starts with a backslash that's running through javascript, you have to escape it by adding another backslash. Also, because of what you want to do in 2B, you'll want to write your search expression with subexpressions so you can delete the comma:
{findWhat:"(\\u+ \\u+)(,)"}
{changeTo:"By $1"}
To explain what's going on here in the changeTo, you're inserting "By" and a space, followed by the contents of the first set of parentheses ($1 = your reporters' names), and by omitting $2 (the contents of the second set of parens), you'll delete the comma.
Offhand I can't think how you'd do #3 using FindChangeList. It could undoubtedly by done via scripting, provided the story is all in one text flow.
I'll leave it to the folks who do know javascript to recommend a book!
Mary Posner wrote:
I'll leave it to the folks who do know javascript to recommend a book!
4. Peter Kahrel's "Scripting InDesign with Javascript" specifically targets the ID + JS combination: http://shop.oreilly.com/product/9780596802530.do
Question 4
Check out also Automating Adobe InDesign CS4 with ExtendScript by Shirley W. Hopkins
Mary Posner - Thanks for the assistance. Your solutions worked out great.
I have a follow up on question #2 - What would be the easiest way to modify the grep search to look for two or more upper case words followed by a comma?
Jongware and Kasyan Seretsky - Thanks for the recommendations. I'll check them out.
3. I am also looking for a way to find a reporter's name (which is at the beginning of the article) and then add that reporter's contact information at the end of the article
I wrote a somewhat similar script which you can use as a starting point.
I am not having much luck cracking #3 (I am also looking for a way to find a reporter's name (which is at the beginning of the article) and then add that reporter's contact information at the end of the article). Any suggestions?
• • • • •
EXAMPLE:
By PETER PARKER
DAILY BUGLE
Text text text text text text text text text text text.
Text text text text text text text text text text text.
Text text text text text text text text text text text.
• • • • •
The script would find "PETER PARKER"
And then would jump to the end of the article and insert "Peter Parker is a reporter with the Daily Bugle and can be reached at 555-5555."
Any help would be appreciated. Thanks in advance.
I am looking to build a script that will look for a reporter's name (which is at the beginning of the article) and then will move to the end of the article add that reporter's contact information at the end of the article. I am not sure this can be done with FindChangeByList.
You can put something at the end of a story with something like this:
| grep | {findWhat:"^((.+\\r)+)"} | {changeTo:"$1\\rthis is at the end\\r"} | {} |
So you should be able to have a series of searches for the various writers:
| grep | {findWhat:"(By Peter Parker\\r)((.+\\r)+)"} | {changeTo:"$1$2Peter Parker is a reporter blah blah\\r"} | {} |
And then style it with
| grep | {findWhat:"(is a reporter blah blah)"} | {appliedParagraphStyle:"shirttail",changeTo:"$1"} | {} |
\Z matches "end-of-story.
Missing from Adobe's list at http://help.adobe.com/en_US/indesign/cs/using/WSFB3603CC-8D84-48d8-9F7 7-F3E0644CB0B6a.html#WSa285fff53dea4f8617383751001ea8cb3f-6f59a ...
Here is what I put together. Thanks for the assistance.
//Reporters taglines.txt
//
// FIND ALL DOUBLE RETURNS AND REPLACE WITH SINGLE RETURN
// If you don't do this first, the tagline will be placed at the first empty return
//
grep {findWhat:"\r\r+"} {changeTo:"\r"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}
//
// --------------------------------------------------------------------- --------------------------------------------------------
//
// FIND BOTTOM OF ARTICLE AND ADD EXTRA RETURN
// Not all reporters will put a return at the next of their articles
//
grep {findWhat:"((.+\\Z)+)"} {changeTo:"$1\\r"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}
//
// REPORTER'S TAGLINE
grep {findWhat:"(PARKER\\r)((.+\\r)+)"} {changeTo:"$1$2\\rPeter Parker is a reporter for The Daily Bugle. He can be reached at 555-555-5555 or by email at peter.parker@thedailybugle.com."} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}
//
//APPLYING "BODY-RAG-ITALICS" TO TAGLINE
text {findWhat:"for The Villages Daily Sun. He can be reached at"} {appliedParagraphStyle:"Body-Rag-Italics"} {includeFootnotes:true, wholeWord:false, caseSensitive:false}
North America
Europe, Middle East and Africa
Asia Pacific