5 Replies Latest reply on Jan 26, 2011 12:25 AM by Kasyan Servetsky

    [JS CS3] Making the #includepath work

    Tom Tomasko Level 1

      Hello,

       

      I have a script that will be used on both PCs and Macs. As the script refers to many other scripts I need a path to them. However there is something wrong with the following line:

       

      #includepath "myPath+'/FormatResources/'"

       

      I get an error message that says the firstScript.jsxinc cannot be found. Well, it and about many others that follow are there but the path to them is failing. I cannot see what is wrong, nor can find where in the ESTK data browser the #includepath statement might be.

       

      Any help would be appreciated.

       

      Tom

       

      if(File.fs == "Macintosh"){   
           var myPath = "~/Library/Preferences/Adobe InDesign/Version 5.0/Scripts/Scripts Panel" ;//Macs
           }//end if
      else {
           var myPath = "~/Application Data/Adobe/InDesign/Version 5.0/Scripts/Scripts Panel";//PCs
           }//end else

       

      #includepath "myPath+'/FormatResources/'"

      #include "_firstScript.jsxinc"

        • 1. Re: [JS CS3] Making the #includepath work
          [Jongware] Most Valuable Participant

          I'm guessing, but don't worry -- it's an educated guess!

           

          Lines starting with '#' are not really part of Javascript-the-language, so you cannot use Javascript command syntax in them. Concatenating two strings this way is Javascript syntax, as is looking up a string value from a variable.

          Since this line doesn't get parsed and evaluated, everything inside the "quotes" is treated as being the path name, and the path name

           

          myPath+'/FormatResources/'

           

          is not found on your system.

           

          [Edit] I forgot to add a solution. Since the script will (presumably) be run from the Scripts panel, you can use this variable

           

          app.activeScript.fullName

           

          to get the effective path of the script that's running. You can tack on "FormatResources" to get to your data.

          1 person found this helpful
          • 2. Re: [JS CS3] Making the #includepath work
            Kasyan Servetsky Level 5

            Tom,

             

            You can add one or more paths after the #include statement separating them by the semicolon (;)

             

            Try this:

            #includepath "~/Library/Preferences/Adobe InDesign/Version 5.0/Scripts/Scripts Panel;~/Application Data/Adobe/InDesign/Version 5.0/Scripts/Scripts Panel"
            #include "_firstScript.jsxinc"

             

            Kasyan

            • 3. Re: [JS CS3] Making the #includepath work
              Harbs. Level 6

              If I'm not mistaken, "#include" is relative to Folder.current which by default is the folder of the active script...

               

              Harbs

              • 4. Re: [JS CS3] Making the #includepath work
                Tom Tomasko Level 1

                Thanks everyone. Kasyan's solution works just fine.

                • 5. Re: [JS CS3] Making the #includepath work
                  Kasyan Servetsky Level 5

                  I was leafing through the InDesign and xml technical reference and remembered another way to get the glue code:

                  // Locate and run the glue code.jsx file
                  var myFilePath = app.filePath + "/Scripts/xml rules/glue code.jsx";
                  if(File(myFilePath).exists == false){
                       myFilePath = File.openDialog("Locate the file: glue code.jsx");
                  }
                  if(myFilePath != null){
                       var myFile = File(myFilePath);
                       app.doScript(myFile);
                       main();
                  }
                  
                  function main() {
                       // do something here
                  }