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

ReferenceError: open is not a function

Community Beginner ,
May 04, 2017 May 04, 2017

Copy link to clipboard

Copied

I've written the following script to iterate through a hierarchy of directories (using some code on this forum), then it opens any PDF files and resaves them without any downsampling. It works great, except when it's run for a while it has two issues:

1) It always seems to crap out after about 1400 files processed, it simply errors out in the code somewhere which has worked fine in the previous 1399 files. If I restart, it works fine again - this seems to happen with every photoshop script I've worked on (I usually have to process over 50,000 files in a batch, so I just have to keep rerunning things over and over), I don't know if there is a memory leak or something, but at some point during a run of a lot of files (usually after 1400 openings or so), something simply fails.

2) My main problem right now is that after a running this on about 8100 files (in 4 different sessions), the script has simply stopped working, giving me the error message:

ReferenceError: open is not a function

Now, as I said, this script has worked perfectly for two days (other than issue #1), and it seems to do this no matter what the input file is. This happened once yesterday and it just seems like after a day it started working again today until it failed again. Has anyone experienced this before and have a solution? I have no idea why this would suddenly change when the code hasn't:

var topFolder = new Folder('//192.168.0.25/Assets');

var fileandfolderAr = scanSubFolders(topFolder,/\.(pdf)$/i);

function getPDFSaveOptions()

{

    var pdfOpts = new PDFSaveOptions();

    pdfOpts.downSample = PDFResample.NONE;

    pdfOpts.generateThumbnails = true;

    pdfOpts.preserveEditability = true;  

    return pdfOpts;

}

function scanSubFolders(tFolder, mask) { // folder object, RegExp or string

    var sFolders = new Array();

    var allFiles = new Array();

    sFolders[0] = tFolder;

    for (var j = 0; j < sFolders.length; j++){ // loop through folders        

        var procFiles = sFolders.getFiles();

        for (var i=0;i<procFiles.length;i++){ // loop through this folder contents

            if (procFiles instanceof File ){

                //if(mask==undefined) allFiles.push(procFiles);// if no search mask collect all files

                if (procFiles.fullName.search(mask) != -1)

                {

                   $.writeln(fileIndex + " " + procFiles);

                   try

                   {

                       var docRef = open(procFiles); <----- FAILS HERE

                       docRef.saveAs(new File(docRef.fullName), getPDFSaveOptions(), false, Extension.LOWERCASE);       

                       docRef.close();

                   }

                   catch(e){ alert(e); }                         

                   fileIndex++;

                }

        }else if (procFiles instanceof Folder){

            sFolders.push(procFiles);// store the subfolder

            scanSubFolders(procFiles, mask);// search the subfolder

         }

      }

   }

   return [allFiles,sFolders];

};

TOPICS
Actions and scripting

Views

451

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
Adobe
Community Beginner ,
May 04, 2017 May 04, 2017

Copy link to clipboard

Copied

Looks like there was a name clash somewhere, adding the following to the top seemed to fix issue #2:

     #target photoshop

Still wondering what causes #1 though!

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 ,
May 04, 2017 May 04, 2017

Copy link to clipboard

Copied

LATEST

What kind of file does it fail on.  I do not see any file filtering being done.  Is it a file type supported by Photoshop that is failing to open.  I see your processing .PDF files but  the getFiles  does not look  to me like it is filtering  just pdf but I do not know Javascript I just hack

JJMack

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