• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

InDesign Error for FindChangeByList Script (which I slightly customized)

New Here ,
Nov 21, 2022 Nov 21, 2022

Copy link to clipboard

Copied

Hi,

I'm new to scripting, but I don't understand how this error could come from my customization because it refers to a line that I did not edit. This is basically identical to the built-in script called FindChangeByList found in the Scripts Panel under Application > Samples > JavaScript. The only thing I changed was the location of the file that contains the FindChange List. I'll paste the script below and highlight the portion that the error is referring to.

 

Error2_FindChangeByList_script.PNG

 main();
function main(){
var myObject;
//Make certain that user interaction (display of dialogs, etc.) is turned on.
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
if(app.documents.length > 0){
if(app.selection.length > 0){
switch(app.selection[0].constructor.name){
case "InsertionPoint":
case "Character":
case "Word":
case "TextStyleRange":
case "Line":
case "Paragraph":
case "TextColumn":
case "Text":
case "Cell":
case "Column":
case "Row":
case "Table":
myDisplayDialog();
break;
default:
//Something was selected, but it wasn't a text object, so search the document.
myFindChangeByList(app.documents.item(0));
}
}
else{
//Nothing was selected, so simply search the document.
myFindChangeByList(app.documents.item(0));
}
}
else{
alert("No documents are open. Please open a document and try again.");
}
}
function myDisplayDialog(){
var myObject;
var myDialog = app.dialogs.add({name:"FindChangeByList"});
with(myDialog.dialogColumns.add()){
with(dialogRows.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:"Search Range:"});
}
var myRangeButtons = radiobuttonGroups.add();
with(myRangeButtons){
radiobuttonControls.add({staticLabel:"Document", checkedState:true});
radiobuttonControls.add({staticLabel:"Selected Story"});
if(app.selection[0].contents != ""){
radiobuttonControls.add({staticLabel:"Selection", checkedState:true});
}
}
}
}
var myResult = myDialog.show();
if(myResult == true){
switch(myRangeButtons.selectedButton){
case 0:
myObject = app.documents.item(0);
break;
case 1:
myObject = app.selection[0].parentStory;
break;
case 2:
myObject = app.selection[0];
break;
}
myDialog.destroy();
myFindChangeByList(myObject);
}
else{
myDialog.destroy();
}
}
function myFindChangeByList(myObject){
var myScriptFileName, myFindChangeFile, myFindChangeFileName, myScriptFile, myResult;
var myFindChangeArray, myFindPreferences, myChangePreferences, myFindLimit, myStory;
var myStartCharacter, myEndCharacter;
var myFindChangeFile = myFindFile("C:/Users/kallista.vera/AppData/Roaming/Adobe/InDesign/Version 18.0/en_US/Scripts/Scripts Panel/Find & Change/FindChangeLists/FindChangeList-kjv.txt")
if(myFindChangeFile != null){
myFindChangeFile = File(myFindChangeFile);
var myResult = myFindChangeFile.open("r", undefined, undefined);
if(myResult == true){
//Loop through the find/change operations.
do{
myLine = myFindChangeFile.readln();
//Ignore comment lines and blank lines.
if((myLine.substring(0,4)=="text")||(myLine.substring(0,4)=="grep")||(myLine.substring(0,5)=="glyph")){
myFindChangeArray = myLine.split("\t");
//The first field in the line is the findType string.
myFindType = myFindChangeArray[0];
//The second field in the line is the FindPreferences string.
myFindPreferences = myFindChangeArray[1];
//The second field in the line is the ChangePreferences string.
myChangePreferences = myFindChangeArray[2];
//The fourth field is the range--used only by text find/change.
myFindChangeOptions = myFindChangeArray[3];
switch(myFindType){
case "text":
myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
break;
case "grep":
myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
break;
case "glyph":
myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
break;
}
}
} while(myFindChangeFile.eof == false);
myFindChangeFile.close();
}
}
}
function myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
//Reset the find/change preferences before each search.
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences = NothingEnum.nothing;
var myString = "app.findTextPreferences.properties = "+ myFindPreferences + ";";
myString += "app.changeTextPreferences.properties = " + myChangePreferences + ";";
myString += "app.findChangeTextOptions.properties = " + myFindChangeOptions + ";";
app.doScript(myString, ScriptLanguage.javascript);
myFoundItems = myObject.changeText();
//Reset the find/change preferences after each search.
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences = NothingEnum.nothing;
}
function myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
//Reset the find/change grep preferences before each search.
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences = NothingEnum.nothing;
var myString = "app.findGrepPreferences.properties = "+ myFindPreferences + ";";
myString += "app.changeGrepPreferences.properties = " + myChangePreferences + ";";
myString += "app.findChangeGrepOptions.properties = " + myFindChangeOptions + ";";
app.doScript(myString, ScriptLanguage.javascript);
var myFoundItems = myObject.changeGrep();
//Reset the find/change grep preferences after each search.
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences = NothingEnum.nothing;
}
function myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
//Reset the find/change glyph preferences before each search.
app.changeGlyphPreferences = NothingEnum.nothing;
app.findGlyphPreferences = NothingEnum.nothing;
var myString = "app.findGlyphPreferences.properties = "+ myFindPreferences + ";";
myString += "app.changeGlyphPreferences.properties = " + myChangePreferences + ";";
myString += "app.findChangeGlyphOptions.properties = " + myFindChangeOptions + ";";
app.doScript(myString, ScriptLanguage.javascript);
var myFoundItems = myObject.changeGlyph();
//Reset the find/change glyph preferences after each search.
app.changeGlyphPreferences = NothingEnum.nothing;
app.findGlyphPreferences = NothingEnum.nothing;
}
function myFindFile(myFilePath){
var myScriptFile = myGetScriptPath();
var myScriptFile = File(myScriptFile);
var myScriptFolder = myScriptFile.path;
myFilePath = myScriptFolder + myFilePath;
if(File(myFilePath).exists == false){
//Display a dialog.
myFilePath = File.openDialog("Choose the file containing your find/change list");
}
return myFilePath;
}
function myGetScriptPath(){
try{
myFile = app.activeScript;
}
catch(myError){
myFile = myError.fileName;
}
return myFile;
}

TOPICS
Bug , Scripting

Views

316

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 3 Correct answers

Advisor , Nov 21, 2022 Nov 21, 2022

Hello @Kallista262462118vle,

 

Re: but I don't understand how this error could come from my customization because it refers to a line that I did not edit.

The script is erroring at the line app.doScript(myString, ScriptLanguage.javascript); because of the Error sring:"Unterminated string constant" that you can see in error message, this points to an issue with the .txt file.

 

The "Unterminated string constant" error occurs for 3 main reasons:

You have forgotten the closing quote of a string.
You haven

...

Votes

Translate

Translate
Community Expert , Nov 21, 2022 Nov 21, 2022

To add to Mike's answer, I suggest you try using a data file that you know worked previously (eg. the factory default one). If that works then you know it is a problem with your data file. - Mark

Votes

Translate

Translate
Community Expert , Nov 21, 2022 Nov 21, 2022

Hi @Kallista262462118vle,

I tried your script with the FindChangeList shipped with InDesign and I did not get any errors. So it is highely likely that the issue is with your list file. Do check it as per suggestions already made

-Manan

Votes

Translate

Translate
Advisor ,
Nov 21, 2022 Nov 21, 2022

Copy link to clipboard

Copied

Hello @Kallista262462118vle,

 

Re: but I don't understand how this error could come from my customization because it refers to a line that I did not edit.

The script is erroring at the line app.doScript(myString, ScriptLanguage.javascript); because of the Error sring:"Unterminated string constant" that you can see in error message, this points to an issue with the .txt file.

 

The "Unterminated string constant" error occurs for 3 main reasons:

You have forgotten the closing quote of a string.
You haven't escaped characters in the string correctly.
The string is split across multiple lines incorrectly.

 

Regards,

Mike

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2022 Nov 21, 2022

Copy link to clipboard

Copied

To add to Mike's answer, I suggest you try using a data file that you know worked previously (eg. the factory default one). If that works then you know it is a problem with your data file. - Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2022 Nov 21, 2022

Copy link to clipboard

Copied

LATEST

Hi @Kallista262462118vle,

I tried your script with the FindChangeList shipped with InDesign and I did not get any errors. So it is highely likely that the issue is with your list file. Do check it as per suggestions already made

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines