Skip to main content
Known Participant
July 14, 2021
Question

How to Save Setting in Script

  • July 14, 2021
  • 3 replies
  • 2024 views

I know, The Script File is save setting Like Check Box, Dropdownmenu, Edittext etc..

Can you tell me @JJMack  How could you have save setting in script ?

This topic has been closed for replies.

3 replies

Stephen Marsh
Community Expert
Community Expert
July 15, 2021

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!

MXKSAuthor
Known Participant
July 15, 2021

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.

suppose,

prefs.txtbox = "AS"

//button clicked it saved

*************************

then again

prefs.txtbox = "AS"

//button clicked alert "already exists"

Stephen Marsh
Community Expert
Community Expert
July 15, 2021

So why not use an if  or while conditional to check if var equals value?

Legend
July 14, 2021

MXKSAuthor
Known Participant
July 15, 2021

I have seen Using Json for saving illustrator script settings. But Can't find exact answar !

Legend
July 15, 2021

Why not?

How is the question, such is the answer

There is a solution.

You just need to turn on your head.

Legend
July 14, 2021

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;

MXKSAuthor
Known Participant
July 14, 2021

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