7 Replies Latest reply on Aug 30, 2017 1:31 AM by Tomas Sinkunas

    Can you set a file to "self destruct" after a set period of time?

    GratefullyDyed Level 1

      Hi!

       

      I have someone interested in using a script that I had made. I would like to let them use it but I want to have some control over the period of time they are able to. My plan is to encrypt the script and hopefully set it to self destruct after a year, so they need a new file from me to continue using it. This way, if we stop doing business they can no longer use the script.

       

      Is there a simple way to do something like this?

       

      Thanks!

        • 1. Re: Can you set a file to "self destruct" after a set period of time?
          Silly-V Adobe Community Professional

          In the script, you can easily put in a statement to exit the script based on a javascript Date.

          Check this snippet out: it has an expiration date of Dec 31, 2018 at 11:59pm.

           

          #target illustrator

          function test(){

            // year = 2018, months = 11 (0-11), date = 31 (1-31), hours = 23 (0-23), minutes = 59 (0-59)

            var expirationDate = new Date(2018, 11, 31, 23, 59);

            var today = new Date();

            if(today.getTime() > expirationDate.getTime()){

              alert("Please contact me to get a new version of this script.");

              return;

            } else {

              alert("Your script is still valid.");

            }

          };

          test();

           

          Then, out of your ExtendScript Toolkit, you can export the jsx script file as .jsxbin, which is a binary format that a human can't read or edit!

          1 person found this helpful
          • 2. Re: Can you set a file to "self destruct" after a set period of time?
            GratefullyDyed Level 1

            Thanks Silly! That seems like it will work perfectly. I will give it a try asap.

            • 3. Re: Can you set a file to "self destruct" after a set period of time?
              Tomas Sinkunas Adobe Community Professional

              Some time ago I wrote this snippet AE Script: Expired — Bitbucket and I always include it into my scripts I sent to client, until the payment comes through. It's a safe way to ensure that your script will not be useable after some given time.

               

              Check it out.

              • 5. Re: Can you set a file to "self destruct" after a set period of time?
                GratefullyDyed Level 1

                I was able to get both of those to give the dialogue box but I was unable to get it to actually exit the script. I am not sure what I would put in to have it exit the script if expired.

                • 6. Re: Can you set a file to "self destruct" after a set period of time?
                  Silly-V Adobe Community Professional

                  It's in how you write the script: you've got to put the snippet in somewhere in the beginning of the script you have, and have that return statement exit the script and do nothing else. You'll notice my snippet is inside a function, so you may want to take the innards of it and paste it as the first lines of your existing script. Use just this part:

                    // year = 2018, months = 11 (0-11), date = 31 (1-31), hours = 23 (0-23), minutes = 59 (0-59)

                    var expirationDate = new Date(2018, 11, 31, 23, 59);

                    var today = new Date();

                    if(today.getTime() > expirationDate.getTime()){

                      alert("Please contact me to get a new version of this script.");

                      return;

                    } else {

                      alert("Your script is still valid.");

                    }

                  • 7. Re: Can you set a file to "self destruct" after a set period of time?
                    Tomas Sinkunas Adobe Community Professional

                    It all depends on how your script is structured, but as Silly-V mentioned, you should check conditions somewhere at the start of your script.

                     

                    Here's a small example on how I would do that.

                    1. Wrap your entire script to an iIFE to avoid leaking variables to global namespace.

                    2. Set expiration date as string or a number;

                    3. Check if time period expired. If expired, exit the script, if still valid - call your main function myScript();

                     

                    This technique assumes that you have your script logic inside myScript() function;

                     

                    // Wrap script to IIFE to avoid leaking variable to global namespace.
                    (function () {
                    
                        // Set scripts expiration date in format YYYYMMDD;
                        var expirationDate = "2010925";
                    
                        // Check if time period expired.
                        // If expired, exit the script.
                        // If still valid, execute your script.
                        if (expired(expirationDate)) {
                            return alert("You cannot run this script anymore because you haven't paid the developer.", "Error", true);
                        } else {
                            myScript();
                        }
                    
                        function myScript() {
                            // YOUR SCRIPT GOES HERE
                    
                    
                            alert("Time period is valid. Script should run.");
                    
                    
                            // YOUR SCRIPT END HERE
                        }
                    
                    
                        function expired(expirationDate) {
                            var date = new Date(),
                                yy = date.getFullYear(),
                                mm = date.getMonth() + 1,
                                dd = date.getDate(),
                                today;
                    
                    
                            mm = (mm < 10) ? "0" + mm : mm;
                            dd = (dd < 10) ? "0" + dd : dd;
                            today = yy.toString() + mm.toString() + dd.toString();
                            expirationDate = (typeof expirationDate !== "String") ? expirationDate.toString() : expirationDate;
                            return (today > expirationDate) ? true : false;
                        }
                    })();