I'm working on a Photoshop script in JavaScript using ExtendScript. My script allows some user input, and I'd like to save it between uses. That is, I'm looking for a way to save a simple string or numeric value under a particular key so that I'll be able to access it on subsequent uses of the script. Simply put, I want to save a preference for my script. How do I do that?
Even better would be to be able to save at least some preferences on a per-document basis. Is that possible? That is, can I store an arbitrary bit of data with a document?
For per-document prefs I suggest the use of the XMP Metadata. You can find example snippet here: http://forums.adobe.com/thread/790973. You can leverage AdobeXMPScript library to create your own namespace like it is suggested in the link by Paul Riggott.
You can use put/get custom options to save preference parameters that persist across Photoshop launches:
You have some options. You can create a text file and write to it using the
File
object:...if you wanted your preferences tied to the script itself.
If you want per-document preferences you could write a string to one of the metadata fields of the file your working on using
Document.info
like this (using the 'instructions' field but you could use any writable field):As for how to actually format the string you could just do it like a simple config file or, if you have a complex user preferences object you could use the
XML
object to construct and serialize it. JSON would be great for this but there is no JSON object in Extendscript, unfortunately.