Skip to main content
Known Participant
July 3, 2023
Question

Photoshop .jsx scripting code I've run 100 times suddenly failing to run + producing errors. Why?

  • July 3, 2023
  • 2 replies
  • 482 views

I've been successfully using this jsx code to run batches in Photoshop:

 


function runBatchAction(inputPath, outputPath, actionName, actionSet, wildcard) {
    wildcard = wildcard || /\.(jpg|jpeg|png)$/i;
    var files = new Folder(inputPath).getFiles(function(file) { return wildcard.test(file.name) });

    var options = new BatchOptions();
    options.destination = BatchDestinationType.FOLDER;
    options.destinationFolder = new Folder(outputPath);
    options.overrideOpen = false;
    options.overrideSave = true;

    options.fileNaming = [FileNamingType.DOCUMENTNAMEMIXED, FileNamingType.EXTENSIONLOWER];
    app.batch(files, actionName, actionSet, options);
 
    // After batch processing, iterate over the files and replace dashes with spaces
    var outputFolder = new Folder(outputPath);
    var outputFiles = outputFolder.getFiles();
    for (var i = 0; i < outputFiles.length; i++) {
        var outputFile = outputFiles[i];
        if (outputFile.name.indexOf('-') !== -1) {
            var newFileName = outputFile.name.replace(/-/g, ' ');
            outputFile.rename(newFileName);
        }
    }
}

runBatchAction(
  "C:\\Users\\anton\\Pictures\\CURRENT IMAGE FOLDER", // input folder
  "C:\\Users\\anton\\Pictures\\AUTOMATION ASSETS\\PHOTOSHOP FILES\\INTERMEDIATE IMAGES", // output folder
  "mockup resizing v1", // action name
  "IMAGE RESIZING" // set name
);
 
It's now failing to run correctly, and I get this error in my Python script:
 
Traceback (most recent call last):
File "c:\Users\anton\Documents\photoshop-scripting\image-resizing-v1.py", line 459, in <module>
jsx_file_path = r"C:\Users\anton\Documents\photoshop-scripting\batch-photoshop-steps-v1.jsx"
File "<COMObject Photoshop.Application>", line 3, in DoJavaScriptFile
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Adobe Photoshop', 'General Photoshop error occurred. This functionality may not be available in this version of Photoshop.\n- Error 1220: Illegal Argument\rLine: 63\r-> app.batch(files, actionName, actionSet, options);', None, 0, -2147212704), None)
 
Any clue why this would suddenly start triggering this error, after this exact jsx code has been working just fine this whole time?
This topic has been closed for replies.

2 replies

Known Participant
July 4, 2023

The core problem ended up being, the number of files being passed into app.batch. I was running this script for very large batch sizes that the code apparently couldn't handle. There is most likely some kind of limit on either the number of files it can process at a time, or the amount of text you can pass into app.batch. Either way, the solution was to break the "files" variable up into chunks of 100, and iterate through each chunk of 100, running the app.batch for each separate chunk of files. It appears to be working just fine now.

Known Participant
July 3, 2023

The ONLY thing I can think of is, there might be some "files" limit? I'm doing a bigger batch than previously. 1400+ files. Is there some Photoshop scripting batch limit? Or maybe something where, when I get the files in the code, it's not able to pull them all since there are so many, and it cuts it off at the end or something, producing the error?