We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.
Typically you would write settings to a file and read them out again. Extendscript has good XML support.
You can also use the app.preferences object and save a preference setting as
app.preferences.mypref = 'foo';
var bar = app.preferences.mypref;
If I have Form Inside a Edittext, I have put 20 in Edittext.
I will change Edittext value :- 24
And Form will close ! and Run Again Form Edittext value will see 24 !
Step 1:- I have Form Inside a Edittext Value is 20
Step 2:- I will Change Edittext Value 24 (Save 24 Value in script)
Step 3:- Again Run Form Edittext value will see 24
Putting variable to memory via preferences, so accessing it with next script session? It does not work.
Sorry, I was testing in Bridge not photoshop. :sigh: It would be nice if each app had the same capabilities.
In Bridge, you can use the app preferences object to save arbitrary settings. In Photoshop you have to write to a file.
I thought so you talk about Bridge, but there you don't have to use preferences to store variables. You can use any variable without connection to preferences. It will be remembered.
How is the question, such is the answer
There is a solution.
You just need to turn on your head.
About a month ago I had to do Save for Web with Month & Day Script? for the very first time. This was my first attempt at writing/reading from a text file.
In this case it is just a simple, single string of text to log save file directory path, that could be referenced in two separate scripts:
/////////////////// WRITE PREFERENCE FILE /////////////////// // Select the folder to write to the preference file var prefFilePath = Folder.selectDialog('Select the save folder...', '~/Documents'); // Create the preference file var prefFile = new File('~/Desktop/Pref-File.txt'); // Write the directory path to the pref file // r = read mode | w = write mode | a = append | e = edit prefFile.open('w'); prefFile.write(prefFilePath.fsName); prefFile.close(); prefFile.encoding = 'UTF-8'; // LineFeed options // prefFile.lineFeed = "Unix"; // prefFile.lineFeed = "Windows"; // prefFile.lineFeed = "Macintosh"; // Alert notice alert('Save path written to Desktop log file "Pref-File.txt"'); ////////////////////////////////////////////////////////////
/////////////////// READ PREFERENCE FILE /////////////////// // Pref file location var prefFile = File('~/Desktop/Pref-File.txt'); // Open the pref file: r = read mode | w = write mode | a = append | e = edit var openPrefFile = prefFile.open('r'); // Read the value var prefFileValue = prefFile.readln(); // Pref file value returned alert('Save folder location:' + '\r' + prefFileValue); ////////////////////////////////////////////////////////////
Perhaps one day I'll need to graduate to a JSON or XML file, however I was just happy to get a plain text file working in this case!
I have seen pref file, I know How to write on text file in Script ,
My Question is i have txtbox value already exists.it must alert that it was already exists.else save data.
prefs.txtbox = "AS"
//button clicked it saved
prefs.txtbox = "AS"
//button clicked alert "already exists"
So why not use an if or while conditional to check if var equals value?
At some point I'll post a sample script with reading/writing XML values to save prefs. I used that for quite a while so I have a working implementation that just needs packaging.
Thank you, that would be very useful!
I added an "XMLPrefs" script to my dropbox folder. It has sample code for reading/writing prefs to an XML file.