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.
1 person found this helpful
Just add these two lines at the end of the script.
var f = new File(decodeURI($.fileName));
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
thanks for the help. It worked beautifully. Helped this newbie out quite a bit.
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.