Skip to main content
Inspiring
Jan 22, 2025 1:36 PM UTC
Answered

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

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();



m1b
m1bCorrect answer
Community Expert
Jan 23, 2025 12:11 AM UTC

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

14 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
Jan 23, 2025 12:11 AM UTC

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

Translate
Inspiring
Jan 24, 2025 8:56 AM UTC

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!

Translate
Robert at ID-Tasker
Legend
Jan 22, 2025 2:35 PM UTC

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

 

Translate
Robert at ID-Tasker
Legend
Jan 22, 2025 2:34 PM UTC

Have you seen FindChangeByList script included with InDesign?

 

 

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

 

Translate
exploiter
Participating Frequently
Feb 3, 2026 12:24 PM UTC
exploiter
Participating Frequently
Feb 3, 2026 12:25 PM UTC

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

 

Translate