Skip to main content
Known Participant
May 12, 2009
Answered

JavaScript Error when running FindChangeByList script in CS4

  • May 12, 2009
  • 1 reply
  • 5014 views

Hello there. InDesign CS4 user here running 10.4.11 on a PowerPC G5.

I recently learned GREP and thought of some very useful find/changes that meet our company's needs before laying out text. All of these find/changes work as desired when run using the find/change dialog box. However, when I tried to replace the existing items in the findchangelist.txt file, I'm getting the following Javascript error:

JavaScript Error!

Error Number: 25

Error String: Expected: :

File: /Applications/Adobe InDesign CS4/Scripts/Scripts Panel/Samples/JavaScript/FindChangeByList.jsx

Line: 172

Source:  app.doScript(myString, ScriptLanguage.javascript);

I saw at least one other person has had this problem, but there was no reply posted. I also found similar complaints about the script that comes with InDesign CS4 being "broken," but don't know JavaScript well enough to fix the error. Can anyone help? It would be greatly appreciated.

Matthew

P.S. - In case it's helpful, I'll include the script from the text file below. The only instances where I'm applying formatting to text (instead of replacing text) are the 3rd and 10th lines. This is my first experience with scripting, so go easy on me.

//Pre-layout.txt
//A support file for the InDesign CS4 JavaScript FindChangeByList.jsx
//
//This data file is tab-delimited, with carriage returns separating records.
//
//The format of each record in the file is:
//findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description
//
//Where:
//<tab> is a tab character
//findType is "text", "grep", or "glyph" (this sets the type of find/change operation to use).
//findProperties is a properties record (as text) of the find preferences.
//changeProperties is a properties record (as text) of the change preferences.
//findChangeOptions is a properties record (as text) of the find/change options.
//description is a description of the find/change operation
//
//Very simple example:
//text    {findWhat:"--"}    {changeTo:"^_"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all double dashes and replace with an em dash.
//
//More complex example:
//text    {findWhat:"^9^9.^9^9"}    {appliedCharacterStyle:"price"}    {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}    Find $10.00 to $99.99 and apply the character style "price".
//
//All InDesign search metacharacters are allowed in the "findWhat" and "changeTo" properties for findTextPreferences and changeTextPreferences.
//
//If you enter backslashes in the findWhat property of the findGrepPreferences object, they must be "escaped"
//as shown in the example below:
//
//{findWhat:"\\s+"}
//
text    {findWhat:"--"}    {changeTo:"^_"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all dash-dash and replace with an em dash.
grep    {findWhat:"⁄"}    {changeTo:"/"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all funky slashes and replace with regular slashes.
grep    {findWhat:"\d\/\d"}    {myText.otfFraction = true}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Format opentype fractions.
grep    {findWhat:"(?<=\d) (?=\d\/\d)"}    {changeTo:""}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Remove all spaces from mixed fractions.
grep    {findWhat:"\x{20}\x{20}+"}    {changeTo:"\x{20}"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find multiple spaces and replace with single space.
grep    {findWhat:" +$"}    {changeTo:""}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find trailing spaces and delete.
grep    {findWhat:"([\d\/]+)-([\d\/]+)"}    {changeTo:"$1–$2"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find hyphens in number ranges and replace with en-dashes.
grep    {findWhat:"(?<=\d) (?=seconds?|minutes?|hours?|days?|weeks?|months?|teaspoons?|tablespoons?|cups?|pounds?|ounces?|degrees?|inch|inches|\bto\b|\bby\b)"}    {changeTo:"~S"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Replace spaces after some numbers with non-breaking spaces.
grep    {findWhat:"(\d+)-([\u\l]+)"}    {changeTo:"$1‑$2"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Replace hyphens after numbers with non-breaking hyphens.
grep    {findWhat:"([\u\l]+(?=[-­‑–]))|((?<=[-­‑–])[\u\l]+)"}    {myText.noBreak = true}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all hyphenated words and set to no-break.

This topic has been closed for replies.
Correct answer

Thank you, Ole! The file you sent did just the trick!

Eventually I'd like to create multiple .txt files that I can use to automate some formatting on different book series we publish. To do that, I need to learn more Javascript. Are the resources provided by Adobe (Introduction to Scripting PDF, Adobe InDesign CS4 Scripting Tutorial PDF) the best place to start? Or is there another book or resource that's a better introduction to Javascript? I'd love some recommendations!

Thanks again,

Matthew


Hi Matthew,

For what you're doing, I think Peter Kahrel's O'Reilly e-books on grep and scripting in InDesign would both be good. But there's quite a lot in the Scripting Guide and the associated script archive--I tried to cover the most common uses of scripting.

FYI for everyone following this thread--Matthew's file contained two things that were throwing it off that I didn't see when I looked at his email. In this line:

grep {findWhat:"\d\/\d"} {myText.otfFraction = true} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Format opentype fractions.

...the change properties should be:

{otfFraction:true}

...and in this line:

grep {findWhat:"([\u\l]+(?=[--–]))|((?<=[--–])[\u\l]+)"} {myText.noBreak = true} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all hyphenated words and set to no-break.

...the change properties should be:

{noBreak:true}

Since we're inside a properties record in the above cases, you can't use the the form property = value, you have to use the form property:value. Hope that makes sense!

Thanks,

Ole

1 reply

May 12, 2009

Hi mattaca,

It's most likely that you either a.) didn't save the file as plain text (the Mac OS Text Edit application, for example, does not save as plain text by default), b.) saved as plain text but did not use the type of line end character that the script expects, c.) did not put tab characters between fields in the file, or d.) did not properly "escape" special characters in the GREP strings you entered (all backslashes, for example, have to be entered as "\\").

You can send me the file directly and I'll check it out. My direct email address is under my user name.

Thanks,

Ole

mattacaAuthor
Known Participant
May 13, 2009

Hi Olav. I didn't see an email address on your profile, so I sent you a private message. I checked out all the stuff you mentioned and it looks fine, but i keep getting the same error message, always with the same error number and line. Does the type of .txt encoding matter?

I pasted the GREP strings into TextEdit directly from InDesign's Find/Change dialog box, and they work correctly there. To my knowledge, the only thing that didn't paste correctly was a non-breaking space (~S in GREP, which showed up as some sort of invisible space character in TextEdit) so I keyed it in manually.

I'll attach the .txt file here for you to look at. Any help would be appreciated.

Thanks,

Matthew

P.S. - I'm not sure how to indicate the ChangeProperties when leaving the text as is but applying formatting. That could have something to do with the error.

Correct answer
May 13, 2009

Thank you, Ole! The file you sent did just the trick!

Eventually I'd like to create multiple .txt files that I can use to automate some formatting on different book series we publish. To do that, I need to learn more Javascript. Are the resources provided by Adobe (Introduction to Scripting PDF, Adobe InDesign CS4 Scripting Tutorial PDF) the best place to start? Or is there another book or resource that's a better introduction to Javascript? I'd love some recommendations!

Thanks again,

Matthew


Hi Matthew,

For what you're doing, I think Peter Kahrel's O'Reilly e-books on grep and scripting in InDesign would both be good. But there's quite a lot in the Scripting Guide and the associated script archive--I tried to cover the most common uses of scripting.

FYI for everyone following this thread--Matthew's file contained two things that were throwing it off that I didn't see when I looked at his email. In this line:

grep {findWhat:"\d\/\d"} {myText.otfFraction = true} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Format opentype fractions.

...the change properties should be:

{otfFraction:true}

...and in this line:

grep {findWhat:"([\u\l]+(?=[--–]))|((?<=[--–])[\u\l]+)"} {myText.noBreak = true} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all hyphenated words and set to no-break.

...the change properties should be:

{noBreak:true}

Since we're inside a properties record in the above cases, you can't use the the form property = value, you have to use the form property:value. Hope that makes sense!

Thanks,

Ole