5 Replies Latest reply on Feb 2, 2011 1:39 PM by Michael L Hale

    A method to have the script delete itself?

    josh.toro

      So i currently have c++ calling a .jsx file from photoshop that is saved in a folder. I would like to know if it would be possible to delete the .jsx file from the folder once the script has run from within javascript. Is this possible?

       

      thanks,

      - j

        • 1. Re: A method to have the script delete itself?
          JJMack Most Valuable Participant

          I would think that it would be possible for the script to create a temp file that it could schedule to be run that would be a job to delete the script file from where is has been stored. On a Windows system I have create a Photoshop action+script that creates a displacement map PSD file on the users desktop then use it and after using the displacement map the scripts write a bat file to delete the displacement map psd file and executes the bat file. I think the script would first need to terminate before it could be deleted not be in use.  Therefore the delete would need to be scheduled for execution after shortly after the script terminates or have a delay or a loop in the delete job which is started from within the script to insure the script file gets deleted.  

          • 2. Re: A method to have the script delete itself?
            Michael L Hale Level 5

            Just add these two lines at the end of the script.

             

            var f = new File(decodeURI($.fileName));
            f.remove();

            1 person found this helpful
            • 3. Re: A method to have the script delete itself?
              JJMack Most Valuable Participant

              Michael so your saying that its possible to delete oneself very interesting would have thought that something  would prevent that. I know the script has been read into memory and the jsx file could be closed but I thought that the OS or Photoshop would keep it open or locked so it could not be modified or deleted while it was being interpreted and executed and prevent the script to run an action that would use the same script that keeping the script locked could be used to prevent recursion or modification of itself or by an other process that something could get messed up if the script processor was not reentrant or programmed carefully.

              Thank for the code as a hacker I'm alway on the lookout for things like that from knowledgable programmers like you

              • 4. Re: A method to have the script delete itself?
                josh.toro Level 1

                michael,

                 

                thanks for the help. It worked beautifully. Helped this newbie out quite a bit.

                 

                - j

                • 5. Re: A method to have the script delete itself?
                  Michael L Hale Level 5

                  JJMack, the script has to be read completely into memory before it is interpreted and executed. So if the script file is modified or deleted while being executed it has no effect to the execution of the script in memory. I don't see how locking for possible future use from an action or other script would be workable. How would Photoshop know when to unlock. Photoshop doesn't lock an image file when it is open. I would not think it would lock a script file which can't be edited in Photoshop as documents can.

                   

                  But I didn't know that it is possible for a script to delete itself until I ran a few tests before making my other post.