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

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

Community Beginner ,
Jan 22, 2025 Jan 22, 2025

Copy link to clipboard

Copied

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



TOPICS
Bug , How to , Scripting

Views

156

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 1 Correct answer

Community Expert , Jan 22, 2025 Jan 22, 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 thin

...

Votes

Translate

Translate
Community Expert ,
Jan 22, 2025 Jan 22, 2025

Copy link to clipboard

Copied

Have you seen FindChangeByList script included with InDesign?

 

RobertatIDTasker_0-1737556405092.png

 

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

 

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 ,
Jan 22, 2025 Jan 22, 2025

Copy link to clipboard

Copied

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

 

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 ,
Jan 22, 2025 Jan 22, 2025

Copy link to clipboard

Copied

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

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 Beginner ,
Jan 24, 2025 Jan 24, 2025

Copy link to clipboard

Copied

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!

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 Beginner ,
Jan 24, 2025 Jan 24, 2025

Copy link to clipboard

Copied

Hi Mark!
I'm still working with this script, and I suppose it does not work because of Kyrylics, typographer quotes, 

§, etc. (unusual characters). I tryed to change encoding of the files to the UTF-8 with BOM, but it does not help. I do not want to change at list letters to the ascii, do you have any idea how to make it work? The scripts work., when i run them manually.
Thanks!

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 Beginner ,
Jan 24, 2025 Jan 24, 2025

Copy link to clipboard

Copied

here is my current version of the script (i've commented that scripts which end the running) they all are pretty similar, the only difference I can notice are the unusual characters:
function
runScriptRunner () {
    // Define the scripts folder (relative to InDesign's Scripts folder)
    var scriptsFolder = ""
   
    // 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"),

        File(scriptsFolder + "3Punctuation\\dashes.jsx"),
        File(scriptsFolder + "3Punctuation\\quotes.jsx"),
        // File(scriptsFolder + "3Punctuation\\nested_quotes.jsx"),
       
        //File(scriptsFolder + "4Nonbreak spaces\\spaces_after.jsx"),
        //File(scriptsFolder + "4Nonbreak spaces\\spaces_before.jsx"),
       
        //File(scriptsFolder + "5Cornercases\\adpositions_and_conjunctions.jsx"),
       // File(scriptsFolder + "5Cornercases\\date_month.jsx")
    ];  // Ceate a dialog box
   

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

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

// Run the script runner
runScriptRunner();

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 ,
Jan 29, 2025 Jan 29, 2025

Copy link to clipboard

Copied

Hi @Viktoriia_ sorry for late reply. Text encoding can be tricky. You have already saved the scripts as UTF-8 with BOM which is good. Another thing you can add to the script runner—and maybe each individual script?—is the following line, near the start of the script (before the evals):

$.appEncoding = 'UTF-8';

This sets ExtendScript's own encoding rule, so it might help.

- 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 ,
Jan 29, 2025 Jan 29, 2025

Copy link to clipboard

Copied

@m1b

 

But they work when run from the Scripts panel - so encoding is rather good?

 

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 ,
Jan 29, 2025 Jan 29, 2025

Copy link to clipboard

Copied

LATEST

@Robert at ID-Tasker I think appEncoding comes into play when doScript takes a File as parameter. Also evalFile. It doesn't seem to be a factor when just running a script "directly".

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