4 Replies Latest reply on May 26, 2013 4:41 AM by -hans-

    Script launch counter

    Marco Lugli Level 1

      Hi,

      following the example in this site:

      http://www.indiscripts.com/post/2009/11/can-indesign-script-rewrite-itself

       

      I tried to include the following code in my script for protection purposes:

       

      var cpt = 0;

       

      // the value of cpt is stored

      // in this file at range 10:

      var cptPos = 10;

       

      var updateFile = function(/*int*/n)

          { // 1 <= n <= 9

          var f = File(app.activeScript);

          if ( f.open('e') )

              {

              f.seek(cptPos);

              f.write(''+n);

              f.close();

              }

          }

       

      cpt++;

      alert("You called this script " + cpt + " times");

       

      if (cpt < 5)

          {

          updateFile(cpt);

          // ...

          // your process

          // ...

          alert("Process OK");

          }

      else

          {

          alert("Script disabled");

          }

       

      This code functions if I launch the script from outside my application, while if I launch it from the script panel inside Indesign, it doesn't function anymore.

      I think this should be 'cause of System Administrator's privileges.The file is aimed to rewrite itself, but it does only if I launch it from outside of the Scripts Panel folder.

      Any ideas?

       

      Thanks in advance

        • 1. Re: Script launch counter
          dln385 Level 2

          Can you add some logging to determine where the script is failing?

           

          The problem might be app.activeScript. Try using $.fileName instead; it always refers to the currently executing script.

          • 2. Re: Script launch counter
            -hans- Level 4

            Hi,

             

            thought about a possible 3 characters bom of the file¿ So may be your byte position is 10 + 3 ...

             

             

            Another approach could be to add a label to the app, which is persistant from quitting ...

             

            #target inDesign

             

            app.insertLabel('launchCheck', '0')

             

            x = 0;

            while(x <10){

            x = x+1;

            app.insertLabel('launchCheck', '' + x);

            alert(app.extractLabel('launchCheck'))

                }

            • 3. Re: Script launch counter
              Marco Lugli Level 1

              Sorry, but none of these solutions seem to work. Does anyone has a solid solution for protecting a jsxbin file (usage number limit, date expiration, etc.)?

              • 4. Re: Script launch counter
                -hans- Level 4

                Well,

                 

                first script you've posted works here like expected if you user owns the rights for writing to the file ...

                 

                Labelscript works too. Though this approach will only protect your script on the target ID-installation.

                So, what exactly is your problem? How did you try to implement the labeling?