3 Replies Latest reply on Feb 2, 2009 7:26 AM by Peter Kahrel

    Script Poster

    Level 1
      We used to have a topic that held a script for posting scripts here, but it must have scrolled off into the ether. Here's the script I use. You can see that it was written by "Peter" -- that's Peter Kahrel, who had posted it here in that previous topic.

      Just select your script and then run this script -- it's for either CS3 or CS4.
      //DESCRIPTION: Peter's script poster
      

      with( app.documents.add() )
         {
         textPreferences.typographersQuotes = false;
         with( app.activeDocument.textFrames.add() )
            {
            geometricBounds = [0,0,'700pt','500pt'];
            insertionPoints[0].select();
            }
         }
      app.paste();
      app.findTextPreferences = app.changeTextPreferences = null;
      s = app.documents[0].stories[0];
      search(s, '&', '&');
      search(s, '<', '&lt;');
      search(s, '^t', '  ');
      search(s, '^[', "'" );
      search(s, '^]', "'" );
      search(s, '^}', '"' );
      search(s, '^{', '"' );
      s.insertionPoints[0].contents = '<pre>';
      s.insertionPoints[-1].contents = '</pre>';
      app.select(s.texts[0]);
      app.copy();

      function search(s, from, to) {
        app.findTextPreferences.findWhat = from;
        app.changeTextPreferences.changeTo = to;
        s.changeText();
      }
      Thanks Peter.

      Dave
        • 1. Re: Script Poster
          Harbs. Level 6
          Here's another one which was posted on one of the other scripting forums (I don't remember if it was Illustrator or Photoshop).

          I changed it a bit because the original didn't work on my (Mac) computer. This one should work on both mac and Windows, and will work run under any program which supports ExtendScript (including the ESTK).


          var asciiFile = new File(File.openDialog("Open File to convert","Javascript:*.jsx;"));
          var tempFolder = Folder.temp;
          OutHTM = new File(tempFolder.fsName + "/Code2HTM.txt");
          asciiFile.open("r");
          OutHTM.open("w");
          var FileString = asciiFile.read();
          asciiFile.close();
          OutHTM.writeln("<PRE><BR>");
          for (a=0;a<FileString.length;a++){
            c=FileString[a];
            Write(c);
            }
          OutHTM.writeln("</PRE>");
          OutHTM.close();
          OutHTM.execute();
          function Write(Char){
            switch (Char){
              case '\t' : OutHTM.write("  ");
              break;
              case '&' :  OutHTM.write('&amp;');
              break;
              case '<' : OutHTM.write("&lt;");
              break;
              case '>' : OutHTM.write("&gt;");
              break;
              default : OutHTM.write(Char);
              }
            }
          • 2. Re: Script Poster
            Peter Kahrel Adobe Community Professional & MVP
            I've pruned that script down to this:

            #target indesign;
            
            tf = app.documents.add().textFrames.add ({geometricBounds: [0,0,'700pt','500pt']});
            tf.insertionPoints[0].select();
            app.activeDocument.textPreferences.typographersQuotes = false;
            app.paste();
            app.findGrepPreferences = app.changeGrepPreferences = null;
            replace ('&', '&amp;');
            replace ('<', '&lt;');
            replace ('\\t', '   ');
            replace ("'", "'");
            replace ('"', '"');
            tf.parentStory.insertionPoints[0].contents = '<pre>';
            tf.parentStory.insertionPoints[-1].contents = '</pre>';

            function replace (f, r)
               {
               app.findGrepPreferences.findWhat = f;
               app.changeGrepPreferences.changeTo = r;
               app.activeDocument.changeGrep ()
               }


            Peter
            • 3. Re: Script Poster
              Peter Kahrel Adobe Community Professional & MVP
              HArbs,

              Spotted your script only now. Nice one.

              Peter