0

When I try to run the FindChangeByList script (I quote the whole script below) from the InDesign script panel, there appears to be no result.

When I run the script from Adobe Extend Script Toolkit CC, it gets to this line

app.scriptPreferences.userInteractionLevel = userInteractionLevel.interactWithAll; 

and says that userInteractionLevel is undefined. This happens right at the beginning of the script within the first function main().

I tried commenting-out this line to see what would happen, and it got stuck on the next line

if(app.documents.length > 0){
Error message: "undefined is not an object"

It looks like there is a problem with the app. object? I don't know.
I could not see anyone else online with this issue. Any help is appreciated, thanks.

Here is the relevant part of the script below:

//FindChangeByList.jsx
//An InDesign JavaScript
/*  
@@@BUILDINFO@@@ "FindChangeByList.jsx" 3.0.0 15 December 2009
*/
//Loads a series of tab-delimited strings from a text file, then performs a series
//of find/change operations based on the strings read from the file.
//
//The 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+"}
//
//For more on InDesign/InCopy scripting see the documentation included in the Scripting SDK 
//available at http://www.adobe.com/devnet/indesign/sdk.html
//or visit the InDesign Scripting User to User forum at http://www.adobeforums.com
//
main();
function main(){
    var myObject;
    //Make certain that user interaction (display of dialogs, etc.) is turned on.
    //app.scriptPreferences.userInteractionLevel = userInteractionLevel.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.");
    }
}`
5
  • I think the scripting for CS products is kind of a piece-meal thing: each product has its own scripting engine. I mention this because you may have to look for, and change, the scripting engine inside Adobe Extend Script Toolkit to point it to Indesign's scripting engine.
    – Yorik
    Jul 5, 2022 at 17:42
  • @Yorik thanks for the reply, do you have any ideas how to do that? Jul 6, 2022 at 9:05
  • You need to generally havea #target indesign in the first line.
    – joojaa
    Jul 6, 2022 at 10:14
  • @joojaa It's not letting me mark your answer as the answer but that was it!! Thank you so much! I didn't know that... Jul 7, 2022 at 7:20
  • It is OK to take the comments as prompts and then post your own answer (and accept it). This way the solution is prominent
    – Yorik
    Jul 19, 2022 at 16:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.