Do not know if there´s a way to a script over-write itself.
A thing you could think about is to work with single files (reading and writting the ones). For example, a script could create a *.TXT file in any folder in the system. The script could even write (for example, the necessary preferences) in the file. So, every time user run the script, you could programm that this script could first look into *.TXT file to read it and know the preferences or what´s necessary.
Does it suit your needs?
Yes, a script can overwrite itself - but don't do it. The slightest error will render the script useless.
ExtendScript's File and Folder objects allow you to write files anywhere in the filesystem you have permission to do so.
Use Folder.userData as the base location (typically). You can also use Folder.commonFiles.
var f = new File( Folder.userData.absoluteURI + "/[myScript]/[myScript].txt );
Or some such to get the file location.
Then write your file. If it's a pure script, load it using $.evalFile - enclose it in a try/catch in case there's a syntax error. If it's a text file, read it and get what you need. You can also use an associative array -
var a = ;
a["prop1"] = "Fred";
a["prop2"] = "Barney";
Then, with your file:
f.write( a.toSource() );
That'll create a json file. To read that back into your script:
var a = eval( f.read() );
Hey Bob… are you lost this is the AI scripting forum and that's the first time in what may be 5 years I've seen "Staff" post…
Now that I need to eat my hat… Im going to need a pint to help it down…
Not lost, still watch all the scripting forums, and I even make a post now and then.
My job shifted from suite extensions to some back end system work and most recently on the CC admin UI.
rats!! now I won't be able to say "we never see 'staff' in this forum"
It's good to know that someone's going to keep Carlos and me in check…