3 Replies Latest reply on Nov 10, 2010 10:45 AM by jmituzas

    .vbs script to execute .jsx script or re-write .jsx to .vbs

    jmituzas

      OK I have 2 options here to get the job done

       

      First and Probably the easiest a way to execute a .jsx script from a .vbs script.

       

      What I need to do is run a .vbs script that will read info from a tab-delimited text file (depending on which tab) and write in the 3 Variables to a .jsx script used with InDesign. Afterwards have the script run the .jsx script.

       

      Or I can re-write the .jsx script into the exsisting .vbs script (much harder)

       

      Here is the script I will have to convert into .vbs if that is the case other wise I will have to find a way to execute this script from the .vbs script:

       

      // this file is named WebCard.jsx
      //
      //An InDesign CS5 JavaScript.
      //
      // INSTRUCTIONS:
      // make sure you save your merged doc before running script !
      // Save as P:/RxCut/In Design Implementation/group#/brand~WebCard~group#.indd
      // Edit lines 23 - 25 with appropriate data
      // Make sure not to remove any quotes or simi-colon for end of statement.
      // Enjoy
      
      main();
      
      function main(){
          mySetup();
          mySnippet();
          myTeardown();
      }
      
      //<setup>
      function mySetup(){
                  
          group = "RXC353";
          brand = "Generic";
          date = "11092010";
      
      // DO NOT EDIT BELOW THIS LINE !!!
      
          dirPath =  "P:/RxCut/In Design Implementation/" + group  + "/";
      app.open(File(dirPath + brand + "~WebCard~" + group  + ".indd")); 
          
          //If the master spread contains more than a single
          //page, delete the additional pages.
          
          }
              {
                  contents:SpecialCharacters.autoPageNumber
              }
          
        
      //</setup>
      
      //<snippet>
      function mySnippet(){
          //<fragment>
          //Ordinarily, exporting a document to EPS would create a single EPS file
          //for every page in the document (as EPS is a single-page format). We'll 
          //export each page separately, because we want to control the file name.
          var myPageName, myFilePath, myFile;
          var myDocument = app.documents.item(0);
          var myBaseName = myDocument.name;
          for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){
              myPageName = myDocument.pages.item(myCounter).name;
              app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;
              app.jpegExportPreferences.resolution = 96;
              app.jpegExportPreferences.pageString = myPageName;  
             
                switch(myPageName) {
              case "1" : myPageName = "EN FRONT WebCard";
                  docType = "Web/Web Cards/" break;
              case "2" : myPageName = "EN BACK WebCard";
                  docType = "Web/Web Cards/" break;
              case "3" : myPageName = "ES FRONT WebCard";
                  docType = "Web/Web Cards/" break;
              case "4" : myPageName = "ES BACK WebCard";
                  docType = "Web/Web Cards/" break;
          }
              //The name of the exported files will be the base name + the 
              //page name + ".pdf". If the page name contains a colon (as it will 
              //if the document contains sections), then remove the colon.
              fileName = group + " " + myPageName + " " + date + ".jpg";
              
              myFilePath = dirPath + docType + fileName;
              myDocument.exportFile(ExportFormat.jpg, File(myFilePath), false);
          }
          //</fragment>
      }
      //</snippet>
      
      //<teardown>
      function myTeardown(){
      }
      //</teardown>
      

       

      Any help will be greatly appreciated,

      Thanks in advance,

      Joe

        • 1. Re: .vbs script to execute .jsx script or re-write .jsx to .vbs
          [Jongware] Most Valuable Participant

          Just a Q:

           

          function(){return A.apply(null,[this].concat($A(arguments)))}

          .. write in the 3 Variables ..

           

          Are those the ones mentioned at the top of the script -- "Edit lines 23 - 25 with appropriate data"?

           

          Because if that's all,

           

          function(){return A.apply(null,[this].concat($A(arguments)))}

          .. First and Probably the easiest a way to execute a .jsx script from a .vbs script..

           

          I'd happily disagree

          • 2. Re: .vbs script to execute .jsx script or re-write .jsx to .vbs
            jmituzas Level 1

            I  can fill in 2 of the 3 varibles rather easily with the info you had given, but this is the one I am  having problems with putting into a .jsx script, the vbs version I  am having problems reading tabs from a .jsx file is why I have created  these files in .vbs see below for the .vbs file:

             

                Call TwoDimensionArrayTest
                Sub TwoDimensionArrayTest
            
                Dim fso
                Dim oFile
                Dim arrline
                Dim arrItem
                Dim i
                Dim arrMain()
                Dim sFileLocation, strResults
                Dim filesys, folder, path 
            
                Const forReading = 1
                Const ForWriting = 2
                
            strFolder = "P:\RxCut\In Design Implementation\build\Co-Brand\"
            mkdir = "P:\RxCut\In Design Implementation\"
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            For Each objFile In objFSO.GetFolder(strFolder).Files
                If Right(LCase(objFile.Name), 4) = LCase(".txt") Then
                
                    ' The file contains on each line:
                ' Text1 (tab) Text2 (tab) Text3 (tab) Text4
                ' Text5 (tab) Text6 (tab) Text7 (tab) Text8
            'etc etc
            
            Set fso = CreateObject("Scripting.FileSystemObject")
                    sFileLocation = objFile.Name
                    
                    Set oFile = fso.OpenTextFile(objFile.Name, forReading, False)
                    
                Do While oFile.AtEndOfStream <> True
                    strResults = oFile.ReadAll
                Loop
                
                ' Close the file
                oFile.Close
                
            ' Release the object from memory
                Set oFile = Nothing
                
            ' Return the contents of the file if not Empty
                If Trim(strResults) <> "" Then
                    
                    ' Create an Array of the Text File
                    arrline = Split(strResults, vbNewLine)
                End If
             
                For i = 0 To UBound(arrline)
                    If arrline(i) = "" Then
                        ' checks for a blank line at the end of stream
                        Exit For
                    End If 
                    
                    ReDim Preserve arrMain(i)
                    
                        arrMain(i) = Split(arrline(i), vbTab)
            
                Next
            
                 'reads info from tab and creates new variables
                 path = arrMain(1)(3)
                 dir = mkdir & path
                 sptFile = strFolder & path & "\WebCard.jsx"
                 
                 set filesys=CreateObject("Scripting.FileSystemObject") 
            If Not filesys.FolderExists(dir) Then 
            Set folder = filesys.CreateFolder(dir) 
            End If
            
                'This will write the group Variable for WebCard.jsx found on row 2 tab 4
                Set objFSO2 = CreateObject("Scripting.FileSystemObject")
                Set objFile2 = objFSO2.OpenTextFile(sptFile, ForReading)
            
                strText = objFile2.ReadAll
                objFile2.Close
                strNewText = Replace(strText, "group = "*";", "group = "arrMain(1)(3)";")
            
                Set objFile = objFSO.OpenTextFile(sptFile, ForWriting)
                objFile.WriteLine strNewText
                objFile.Close
                
                'Moving WebCard.jsx to location to be executed from
                
                 fso.MoveFile sptFile, dir &  "\InDesign~Source"
            
                'Need it to Execute the WebCard.jsx file
                   
             End If 
             Next
            End Sub ' TwoDimensionArrayTest
            

             

            At the end you can see where it is actually editing the jsx file What I still need is to beable to execute the .jsx file or re-write the exsisting .vbs file that reads all text files in a directory and writes what is on tab 4 row 2 to the corresponding .jsx file. So now if I can't execute .jsx script from a .vbs script then how can I the jsx script to read tabs?

             

            Thanks in advance,