8 Replies Latest reply on Mar 16, 2012 8:51 AM by John Hawkinson

    Network Wontwork (har har) -- Advice on file system access with Javascript.

    KuddRoww Level 1

      I'm on a Windows 7 machine. We are connected to a network which is owned by us but adminstered by a third party. I had learned a while ago that Javascript doesn't perform file system tasks. Now the question is how can I circumvent this obstacle? Does this mean I should really just learn VBS instead of Javascript because of the FSO functionality of VBS? I used a lot of MS products anyhow so maybe that's the better route.

       

      Anyhow for now I'm not learning a new programming language so I'm wondering how other people have worked around this issues. What I need to do is push some metadata into InDesign files located all throughout our network. At this point I'm considering the following workflow:

       

      1) Open file(s) with a batch script, figure out how many I can handle at maximum without crashing InDesign or my PC.

      2) Manually run the Metadata script.

      3) Repeat first step until end of file list. (9637 files)

       

      How can I clean-up this a little (BUNCH!)? And how hard would it be to move between VBS and JS, have the VBS to the getting and JS do the doing?

       

      Any and all help you can provide is greatly appreciated,

        • 1. Re: Network Wontwork (har har) -- Advice on file system access with Javascript.
          Peter Spier Most Valuable Participant (Moderator)

          This seems to be more relevant in the scripting forum, so I've moved it...

          • 3. Re: Network Wontwork (har har) -- Advice on file system access with Javascript.
            Muppet Mark Level 5

            Im confused as to what you are trying to do here… ExtendScript has File & Folder objects for dealing with either OS ( basics ).

             

            1) Open file(s) with a batch script, figure out how many I can handle at maximum without crashing InDesign or my PC.

             

            Open one at a time ( why would they crash your machine something wrong with them? )…

             

            2) Manually run the Metadata script. ( what script? )

             

            There is the posibility you could load the XMP library and not even use ID or use Bridge to do some thing similar with file metadata… You would have to give more detail than you have done any which way I think…

            1 person found this helpful
            • 4. Re: Network Wontwork (har har) -- Advice on file system access with Javascript.
              KuddRoww Level 1

              Sorry Mark I'm not the clearest of writers!

              Muppet Mark wrote:

               

              Im confused as to what you are trying to do here… ExtendScript has File & Folder objects for dealing with either OS ( basics ).

               

              1) Open file(s) with a batch script, figure out how many I can handle at maximum without crashing InDesign or my PC.

               

              Open one at a time ( why would they crash your machine something wrong with them? )…

               

              2) Manually run the Metadata script. ( what script? )

               

              There is the posibility you could load the XMP library and not even use ID or use Bridge to do some thing similar with file metadata… You would have to give more detail than you have done any which way I think…

               

              I should state that I'm doing all of this on the assumption that I cannot access network resources without having to interface with some sort of visual dialog. I've come to this conclusion because while I can't app.open() from a network file I can app.open() from a local drive. My assumption is that there's some Javascript sandbox issue at play, my hope is I'm wrong and I'm just going about opening files the wrong way.

               

              What's super strange is that if I modify the script in the following way I can access the file without a problem.

              myFolder = Folder.selectDialog();

              files = myFolder.getFiles("File.indd");

              app.open(files[0]);

               

              Yet I can't directly address the folder reference by myFolder, I have to go through the selectDIalog(). My assumption is that the object is somehow being validated outside of the ExtendScript scope and is then fed back in. So in short I'm trying to find a way around this constraint for the sake of this project and future ones. So I was going to do this:

              //  BATCH FILE LOADS 25 FILES AT A TIME

               

              next()

              function next(){

              while(app.documents.count() !=25){

                  }

              alert()

              Metadata()

              }

              function Metadata(){

                  with (app.activeDocument.metadataPreferences){

                  author = "Guy Fawkes"

                  app.activeDocument.metadataPreferences.copyrightInfoURL="http://www.rebel.com"

                  app.activeDocument.metadataPreferences.copyrightNotice="Some jargon from some overpriced author." 

                  app.activeDocument.metadataPreferences.copyrightStatus=CopyrightStatus.YES

                  app.activeDocument.metadataPreferences.description="Changing the global document one object at a time."

                  app.activeDocument.metadataPreferences.documentTitle="How-to Destroy Functions"

                  app.activeDocument.metadataPreferences.jobName="Rebellion"

                  app.activeDocument.metadataPreferences.keywords=["Chocolate","Zucchini","Cake"]

                  }

                  for(i=0; app.documents.count(); i++){

                      app.documents[0].close(SaveOptions.YES)

                      }

                  next()

              }

               

              So basically I open 25 files at a time with a simple batch file (I'll either throw a time delay on it or a press any key) and then I don't have to worry about "permissions". Also some of the files are extremely old school and/or have been created in some interesting ways and will inevitably jam so it's better to have a queue that I can adjust and know where to step from.


              I did take a look at the XMP library and to be honest it freaked me out a little.  I'm willing to get into Java or something like that to access the Library a little more "literally" (for lack of a better term) but for now I'm a sub novice dummy at all this and it seemed a little over my head. I know it can also be accessed from the scripting interface but again the codes I've taken a look at confuse me. In any case I can learn the XMP library and how to interface with it for the XMP projects, but there are plenty of times where it would be useful to be able to act directly within the file path without having to go through some time consuming graphical interface.

               

              This is the way I'm currently looking at going around the issue, it's a contrived work around  but for what I'm doing it's more effective than thousands of human driven actions. Like if this tutorial was for import:

               

              http://indisnip.wordpress.com/2010/08/17/extract-metadata-with-adobe-xmp-part-2/

              • 5. Re: Network Wontwork (har har) -- Advice on file system access with Javascript.
                Muppet Mark Level 5

                Firstly I think your issues may be down to to how you were trying to open files ( I don't have any issues off our servers ) Give this a try for a starter…

                 

                #target indesign
                
                var f = File.openDialog( 'Please select a network file…' ); 
                
                if ( f != null ) { app.open( f ); } // null is if you cancelled
                
                var myFolder = Folder.selectDialog();
                
                if ( myFolder != null ) { // Ditto here
                  
                          var files = myFolder.getFiles( /\.indd$/i ); // Pass this a regexp to filter
                
                          app.open( files[0] ); // Guessing there is on here…?
                
                };
                

                 

                That apart I would not be going the route you are for adding this data… I didn't try your metadata script but my guess is that it adds this to file XMP in InDesign's namespace… I don't see why you couldn't do this outside of Indesign… Your script didn't appear to be doing anything unique to file but a generic metadata update? You could make, save then use a metadata template in Bridge for that…

                1 person found this helpful
                • 6. Re: Network Wontwork (har har) -- Advice on file system access with Javascript.
                  John Hawkinson Level 5

                  Just to be superclear, because I think Mark didn't say it quite as bluntly:

                   

                  I should state that I'm doing all of this on the assumption that I cannot access network resources without having to interface with some sort of visual dialog. I've come to this conclusion because while I can't app.open() from a network file I can app.open() from a local drive

                  This is false. You can absolutely app.open() from a network file.

                   

                  If you're stuck, a small reproducible test case showing the problem would be great. If it's more than a few lines, it's too complicated. What you posted above is too long. Also, you include a modified script that works but don't show us your unmodified script with the problem! So what's the problem?

                  1 person found this helpful
                  • 7. Re: Network Wontwork (har har) -- Advice on file system access with Javascript.
                    KuddRoww Level 1

                    Thank-you both very much for your helpful insights and comments.  I can access files directly using app.open().

                     

                    What I was screwing up was when I tried to open them directly I used the windows file path instead of the UNIX one. Using the windows path produces some strange file path that clearly will not work and the UNIX one allows me to index a folder and open a file. Good to know! By default if InDesign can't find the file it spits out a message saying it either doesn't exist or there aren't the appropriate permissions required. I assumed the latter to be true.

                     

                    Sub novice rule #1: Check your damned variable before you chuck your script.

                     

                    Thank-you again gentlemen.

                     

                    When I did this:

                    var f = "C:\users\kstaples\desktop\core_indd\CEPE04200_CH1.INDD"

                    alert(f)

                    Script Alert = .../UserskstaplesDesktopCore_INDDCEPE03200A1_001.indd, no wonder InDesign couldn't open the file or index a folder!

                     

                    When I did this:

                    var f = "c/users/kstaples/desktop/core_indd/CEPE04200_CH.INDD"

                    alert(f)

                    Script Alert = ~/Desktop/Core_INDD/CEPE03200A1_001.indd

                    • 8. Re: Network Wontwork (har har) -- Advice on file system access with Javascript.
                      John Hawkinson Level 5

                      Glad you solved it.

                      In case it wasn't totally obvious, (not sure), [one of] the reason[s] this failed:

                       

                      var f = "C:\users\kstaples\desktop\core_indd\CEPE04200_CH1.INDD"

                      Script Alert = .../UserskstaplesDesktopCore_INDDCEPE03200A1_001.indd, no wonder InDesign couldn't open the file

                      Is because backslash is the Javascript string escape character, allowing you to use, e.g., \n to represent a newline, \t for a tab, etc. If you want a literal backslash in your string literal, you must double it. So:

                       

                      var f = "C:\\users\\kstaples\\desktop\\core_indd\\CEPE04200_CH1.INDD";
                      

                       

                      ought to do the trick. (Though it's possible that InDesign wants a leading backlash or forwardlash or something before the drive letter, I'm not really sure.)