Skip to main content
Inspiring
January 27, 2025
Answered

Kyrylics? app.doScript() issues.

  • January 27, 2025
  • 1 reply
  • 221 views

Hello, dear community!
I have a trouble running my scripts, using another script for it. They all work, when I run them manually, but some of them do not even start to run, when i use my script. I suppose that the problem should be in kyrylics. I am not 100% sure, but all the scripts are pretty similar and only the strings in GREP find/change change. 
The path is correct, the ecoding is UTF-8 (without BOM), the scripts without kyrylics run both ways and with it only manually. What could be a problem?

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")
    ];
    

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

Here is an code example which does not run:

function performGREPFindChange(findWhat, changeTo) {
    // Clear previous GREP find/change preferences
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;

    // Set new GREP find/change settings
    app.findGrepPreferences.findWhat = findWhat;
    app.changeGrepPreferences.changeTo = changeTo;

    try {
        // Perform the Find/Change operation
        app.activeDocument.changeGrep();
    } catch (e) {
        alert("Error: " + e.message);
    }
}

performGREPFindChange('(\\d+)\\s*(січня|лютого|березня|квітня|травня|червня|липня|серпня|вересня|жовтня|листопада|грудня)', '$1~S$2');
Correct answer Viktoriia_

Oh I've just got it... It seems the problem must be in the loops where I use the same named variable , and it's JS... Thanks! I've been trying to fix it for 5 days... Like always so obvious solve when you realize it...  
So in some scripts your i in loop becomes bigger than the number of elements in list and it just ends. Be careful with variables namings! 🙂

1 reply

Robert at ID-Tasker
Legend
January 27, 2025

What is the error message? 

 

Inspiring
January 27, 2025

There is no error. And each of the scripts performs if it is alone in the list. somehow some of the scripts seem to stop performance, but they are all just Grep Find/Change. And i try to catch the errors, but they do not appear...

Robert at ID-Tasker
Legend
January 27, 2025

Then you would've to share your example files. 

 

Do you have diacritics / cyrylic characters - anywhere in the file path?

 

Like the name of the user account in the system?