Access to Adobe Illustrator Preferences

AiScripts
2 min readDec 20, 2021

--

Illustrator preferences can be read and changed from the script. Each option is a key of one of four types: Real, Integer, Boolean and String. For example, the Use Preview Bounds checkbox is the Boolean type, that is, it takes only two values true or false .

Illustrator app preferences

Methods

Each data type has its own method. To read the current state:

app.preferences.getBooleanPreference(key)
app.preferences.getIntegerPreference(key)
app.preferences.getRealPreference(key)
app.preferences.getStringPreference(key)

To record a new value:

app.preferences.setBooleanPreference(key, value)
app.preferences.setIntegerPreference(key, value)
app.preferences.setRealPreference(key, value)
app.preferences.setStringPreference(key, value)

For example, a script that toggles Use Preview Bounds each time you start:

var curState = app.preferences.getBooleanPreference(‘includeStrokeInBounds’);
app.preferences.setBooleanPreference(‘includeStrokeInBounds’, !curState);
Toggle Use Preview Bounds

Problems

By adding methods for reading and writing settings, Adobe has not documented all the possible keys for ExtendScript. The community shares their findings, such as developer Ten-A on his blog. You can also find the keys in the AIPreferenceKeys.h file from the Adobe Illustrator SDK.

Even if you find the exact name of the key, there is no guarantee that it will work properly. Example: The Units section stores units for rulers, strokes, and fonts. Let’s use the script to change the units for rulers and fonts in the settings.

app.preferences.setIntegerPreference(‘rulerType’, 6); // 6: px
app.preferences.setIntegerPreference(‘text/units’,6); // 6: px

The old units will remain in the Illustrator panels until you restart it.

Font units bug
Ruler units bug

Also, a script in which the coordinate system is changed will not work correctly. You have to restart Illustrator after changing the flags.

app.preferences.setBooleanPreference (‘isRulerOriginTopLeft’, true); 
app.preferences.setBooleanPreference (‘isRulerIn4thQuad’, true);

--

--

AiScripts
AiScripts

Written by AiScripts

Sergey Osokin. Product Illustrator, Icon Designer, Script Developer (Ai, Ps). Writing about bugs and tricks in Adobe Illustrator scripts