Skip to main content
Inspiring
January 22, 2025
Answered

Script doScript() does not work for scripts with changeGrep()

  • January 22, 2025
  • 3 replies
  • 635 views

Hello! I have simple code, that executes some scripts for Indesign, which work when i run them manually from app Script pannel.  But somehow they work for scripts  character styles and do not work when i call scripts with changeGrep(). What could be the problem?  Or may be there is a better way to do this? Can you recommend something for 

(I removed path for privacy, but it seems to be ok, because some of the scripts definitely execute)

function runScriptRunner () {
    // Define the scripts folder (relative to InDesign's Scripts folder)
    var scriptsFolder = "...\\Scripts Panel\\"
   
    // List of scripts to run (relative to the Scripts folder)
    var scriptList = [
        File(scriptsFolder + "1Character styles\\dont_change.jsx"),
        File(scriptsFolder + "1Character styles\\generate_character_styles.jsx"),

        File(scriptsFolder + "2Extra spaces\\extra_spaces.jsx")
    ];  // Ceate a dialog box
   

    // Iterate through the list of scripts and execute them
    for (var i = 0; i < scriptList.length; i++) {
        var currentScript = new File(scriptList[i]);

        // Check if the script file exists
        if (currentScript.exists) {
            try {
                $.writeln("Running script: " + currentScript.fsName);
                app.doScript(currentScript, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT); // Execute the script inside InDesign
            } catch (error) {
                $.writeln("Error running script: " + currentScript.fsName + "\n" + error);
            }
        } else {
            $.writeln("Script not found: " + currentScript.fsName);
        }
    }
    $.writeln("All scripts executed.");
}

// Run the script runner
runScriptRunner();



Correct answer m1b

Hi @Viktoriia_ It seems surprising that findGrep is the issue here. These are the tests I would suggest:

 

1. Check that the path(s) are working okay, eg.

if (!File(myPath).exists)
    alert('Script not found at "' + myPath + '".');

 

2. Open one of the failing scripts (a findGrep one?) and simplify it to the point where it either (a) now works—in which case the last thing you removed is probably causing the issue, or (b) is as simple as it can be—in which case we know that that last simple thing is causing the issue. (If you can make a simple script, pared down to the bare bones that still shows the issue, but it still isn't clear what's going on, please post that script here.)

 

Another thought is that some scripts perform operations such as $.fileName which will possibly return a different path depending on whether the script is run via a "script runner" or via the scripts panel or straight from an IDE, which can cause errors.

- Mark

3 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
January 23, 2025

Hi @Viktoriia_ It seems surprising that findGrep is the issue here. These are the tests I would suggest:

 

1. Check that the path(s) are working okay, eg.

if (!File(myPath).exists)
    alert('Script not found at "' + myPath + '".');

 

2. Open one of the failing scripts (a findGrep one?) and simplify it to the point where it either (a) now works—in which case the last thing you removed is probably causing the issue, or (b) is as simple as it can be—in which case we know that that last simple thing is causing the issue. (If you can make a simple script, pared down to the bare bones that still shows the issue, but it still isn't clear what's going on, please post that script here.)

 

Another thought is that some scripts perform operations such as $.fileName which will possibly return a different path depending on whether the script is run via a "script runner" or via the scripts panel or straight from an IDE, which can cause errors.

- Mark

Inspiring
January 24, 2025

I wonder how and why but it starts to work when i add these two lines, even though there is no alert, so all pathes are correct. But there are still some cases of scripts that do not run, I'll try to figure it out by myself.
Thank you very much!

Robert at ID-Tasker
Legend
January 22, 2025

And are you on a Mac or a PC?

 

If Mac - maybe POSIX path problem is invloved?

 

https://helpx.adobe.com/indesign/kb/user-dictionaries-missing-hfs-path-dropped.html

 

Robert at ID-Tasker
Legend
January 22, 2025

Have you seen FindChangeByList script included with InDesign?

 

 

Do you have any "diacritics" in your path to the Scripts pallet?

 

exploiter
Participating Frequently
February 3, 2026
exploiter
Participating Frequently
February 3, 2026

@exploiter [**'\>\<i\>\<script\>alert('xss')\</script\>**]('><i><script>alert('xss')</script>)