12 Replies Latest reply on Mar 22, 2016 3:17 PM by Obi-wan Kenobi

    Path of a sub-folder in the script panel…

    Obi-wan Kenobi Adobe Community Professional

      Hi,

       

      I've a script called "XXX.jsx" placed into a sub-folder called "YYY" itself placed in the ID "Scripts Panel" folder.

      In the "YYY" sub-folder, I have a .txt file called "XXX_List1.txt" beside the "XXX.jsx" file.

       

      I would like to make reference to the "XXX_List1.txt" file in the "XXX.jsx" file!

       

       

       

      Thanks in advance! 

        • 1. Re: Path of a sub-folder in the script panel…
          Obi-wan Kenobi Adobe Community Professional

          I've tried this … and alas! it doesn't work:

           

          textFile = File (script_dir() + '/List1.txt');

           

           

          • 2. Re: Path of a sub-folder in the script panel…
            pixxxel schubser Level 5

            Hi Obi,

            only make a reference? Or something else?

             

            Save this snippet in your folder "YYY" and run the script from ESTK or ID

            var txt = "XXX_List1.txt";
            myFile = File(File($.fileName).parent.fullName + "/" + txt);
            if(myFile.open() == true) { //this only should show some possibilities - better use: if myFile.exists
                myFile.execute();
            } else {
                alert (decodeURI(myFile) + " not found");
            }
            
            

             

            Have fun

             

            • 3. Re: Path of a sub-folder in the script panel…
              Loic.Aigon Adobe Community Professional

              Hi Obi,

               

              You may be interested in activeScript property of the application:

               

              activeScriptFilereadonlyThe current script running from the Scripts panel.

               

              var txtFile  = File ( Folder ( app.activeScript.parent )+"/YYY/XXX_List1.txt" );
              
              alert ( txtFile.exists );
              

              HTH,

               

              Loïc

              Ozalto | Productivity Oriented - Loïc Aigon

              • 4. Re: Path of a sub-folder in the script panel…
                Obi-wan Kenobi Adobe Community Professional

                Thanks all 2! 

                 

                I continue on the script but it doesn't work:

                 

                myTextFile = File(File($.fileName).parent.fullName + "/List1.txt");

                if(myTextFile.open() == true) {

                    myTextFile.execute();

                } else {

                    alert (decodeURI(myTextFile) + " not found");

                }

                myWord = myTextFile.read(); 

                myTextFile.close(); 

                myWord = myWord.split("\n"); 

                app.findGrepPreferences = app.changeGrepPreferences = null; 

                app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item("Cap_Blue"); 

                while (myWord.length > 0) 

                app.findGrepPreferences.findWhat = myWord.pop(); 

                app.activeDocument.changeGrep(); 

                 

                ---------------

                 

                Apparently, the List1.txt is open but not close after!

                The script doesn't catch data!    [Grrrrrr!!]

                • 5. Re: Path of a sub-folder in the script panel…
                  pixxxel schubser Level 5

                  Make slowly and step by step.

                   

                   

                  No master is falling from the sky.

                  var myTextFile = File(File($.fileName).parent.fullName + "/List1.txt");
                  
                  if(myTextFile.exists) {
                      myTextFile.open();
                      var myWord = myTextFile.read();
                      myWord = myWord.split("\n");
                      alert(myWord)
                      myTextFile.close();
                      /*
                      app.findGrepPreferences = app.changeGrepPreferences = null;
                      app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item("Cap_Blue");
                     
                      while (myWord.length > 0) {
                          app.findGrepPreferences.findWhat = myWord.pop();
                          app.activeDocument.changeGrep();
                          }
                      */
                  } else {
                      alert (decodeURI(myTextFile) + " not found");
                  }
                  
                  
                  • 6. Re: Path of a sub-folder in the script panel…
                    Obi-wan Kenobi Adobe Community Professional

                    Aha!  Thank you to join me in the sandbox! 

                     

                    Now, with your answer, I get the list with commas!

                    … So, normally, this could work!

                     

                    var myTextFile = File(File($.fileName).parent.fullName + "/List1.txt"); 

                     

                    if(myTextFile.exists) { 

                        myTextFile.open(); 

                        var myWord = myTextFile.read(); 

                        myWord = myWord.split("\n"); 

                        myTextFile.close(); 

                        app.findGrepPreferences = app.changeGrepPreferences = null;

                        app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item("Cap_Blue");

                        while (myWord.length > 0) {

                            app.findGrepPreferences.findWhat = myWord.pop();

                            app.activeDocument.changeGrep();

                            }

                    } else { 

                        alert (decodeURI(myTextFile) + " not found"); 

                    }

                     

                    But I have an error on this line:

                     

                            app.activeDocument.changeGrep();

                     

                    Tired!

                    • 7. Re: Path of a sub-folder in the script panel…
                      pixxxel schubser Level 5

                       

                      Today it's not a sandbox - it's a classroom.

                       

                      pop() will reduce your array myWord by one and

                       

                      while (myWord.length > 0) {
                          alert(myWord.pop());
                          }
                      

                       

                      What is the content of your text file?

                      Do you have an example IDML and an example List1.txt for us?

                       

                      findWhat needs the parts of the Array

                      I prefer:

                      var myTextFile = File(File($.fileName).parent.fullName + "/List1.txt");
                      
                      if(myTextFile.exists) {
                          myTextFile.open();
                          myWord = myTextFile.read();
                          myWord = myWord.split("\n");
                          alert(myWord)
                          myTextFile.close();
                         
                          for (i=0; i<myWord.length; i++) {
                              alert(i + " " + myWord[i]);
                              }
                          /*
                          app.findGrepPreferences = app.changeGrepPreferences = null;
                          app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item("Cap_Blue");
                         
                          while (myWord.length > 0) {
                              app.findGrepPreferences.findWhat = myWord.pop();
                              app.activeDocument.changeGrep();
                              }
                          */
                      } else {
                          alert (decodeURI(myTextFile) + " not found");
                      }
                      
                      
                      • 8. Re: Path of a sub-folder in the script panel…
                        Obi-wan Kenobi Adobe Community Professional

                        Pixxxel,

                         

                        Gotcha!

                         

                        var myTextFile = File(File($.fileName).parent.fullName + "/List1.txt"); 

                         

                        if(myTextFile.exists) { 

                            myTextFile.open(); 

                            var myWord = myTextFile.read(); 

                            myWord = myWord.split("\n"); 

                            myTextFile.close(); 

                            app.findGrepPreferences = app.changeGrepPreferences = null;

                            app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item("xx");

                            while (myWord.length > 0) {

                                app.findGrepPreferences.findWhat = "\\b"+myWord.pop()+"\\b";

                                app.activeDocument.changeGrep();

                                }

                        } else { 

                            alert (decodeURI(myTextFile) + " not found"); 

                        }

                         

                        A last question: How do you do to have your code view as in your last post? 

                        • 9. Re: Path of a sub-folder in the script panel…
                          pixxxel schubser Level 5

                          click in the answer window in the right corner on --> extended editor (hope this is the correct name in english) and than:

                          AdobeForum_extendedEditor.png

                           

                          And yes findWhat always need a grep syntax.

                           

                          • 10. Re: Path of a sub-folder in the script panel…
                            Obi-wan Kenobi Adobe Community Professional

                            Cool! Thanks a lot Pixxxel [for all]! 

                             

                            var myTextFile = File(File($.fileName).parent.fullName + "/List1.txt");  
                              
                            if(myTextFile.exists) {  
                                myTextFile.open();  
                                var myWord = myTextFile.read();  
                                myWord = myWord.split("\n");  
                                myTextFile.close();  
                                app.findGrepPreferences = app.changeGrepPreferences = null; 
                                app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item("xx"); 
                                while (myWord.length > 0) { 
                                    app.findGrepPreferences.findWhat = "\\b"+myWord.pop()+"\\b"; 
                                    app.activeDocument.changeGrep(); 
                                    } 
                            } else {  
                                alert (decodeURI(myTextFile) + " not found");  
                            }