Hi,
I have a script in which I need a number of settings to be changed beforehand.
For example, I need app.preferences.rulerUnits to be set to Units.PIXELS.
As I don't want the end-user to have his settings disrupted, I would like to reset the preferences to whatever they were before I started the script.
Till now I have been using 2 functions, savePSSettings and restorePSSettings
in the first function all the settings that I change in the script are called and saved in an array, while in the second, the array is being used to restore the settings.
Code: Select allfunction savePSSetting()
{
...
psSettingsBackup["app.preferences.rulerUnits"] = app.preferences.rulerUnits
...
app.preferences.rulerUnits = Units.PIXELS.
}
function savePSSetting()
{
...
app.preferences.rulerUnits = psSettingsBackup["app.preferences.rulerUnits"]
}
What I would like to do is to make this procedure more flexible and dynamic without having to write so much code for each preference. Basically, I would like to avoid all the Code: Select allapp.preferences.rulerUnits =
But in my understanding, to do that, I need to be able to call and set a perference by it's name. So something like:
Code: Select allfunction psSet(stringPreferenceName, value)
{
sOriginalValue = eval(stringPreferenceName);
eval(stringPreferenceName = value);
}
This procedure works for getting the preference's value (first line) but not to set the preference's value as the (second line).
Is there a way to set a variable by the string of it's name ? Or are you aware of any other way to backup/restore preferences
Thanks
MiA
Save and Restore mutliple photoshop settings
-
xbytor
Save and Restore mutliple photoshop settings
You may want to try something like this. It has the advantage that all you have to do is add new elements to _savedSettings to get them saved and restored. This could probably be a bit cleaner, but the idea is sound.
Code: Select allvar _savedSettings = {
"app.preferences.rulerUnits": undefined,
"app.preferences.typeUnits": undefined,
};
function saveSettings() {
for (var idx in _savedSettings) {
_savedSettings[idx] = eval(idx);
}
}
function restoreSettings() {
for (var idx in _savedSettings) {
eval(idx + " = " + _savedSettings[idx]);
}
}
Code: Select allvar _savedSettings = {
"app.preferences.rulerUnits": undefined,
"app.preferences.typeUnits": undefined,
};
function saveSettings() {
for (var idx in _savedSettings) {
_savedSettings[idx] = eval(idx);
}
}
function restoreSettings() {
for (var idx in _savedSettings) {
eval(idx + " = " + _savedSettings[idx]);
}
}
-
mia
Save and Restore mutliple photoshop settings
Thanks for your help xbytor !
Based on your code, I've come up with this code which seems to suit my needs best
Code: Select allvar psSettingsBackup = [
["app.displayDialogs", DialogModes.NO],
["app.preferences.rulerUnits", Units.PIXELS]
];
backupRestorePSSettings();
/* Main
programing
script
comes
here */
backupRestorePSSettings();
function backupRestorePSSettings()
{
for(var i=0; i<psSettingsBackup.length; i++)
psSetArray(psSettingsBackup);
}
function psSetArray(aSettings)
{
var sOriginalValue = eval(aSettings[0]);
eval(aSettings[0]+"= "+aSettings[1]);
sNewValue = eval(aSettings[0]);
aSettings[1] = sOriginalValue;
$.writeln("[psSetArray]: "+aSettings[0]+" = "+sNewValue+" (was "+sOriginalValue+")");
}
The advantage of this method is that I have to call a single function to backup and restore settings and can define program defaults in the psSettingsBackup array.
Exactly what I wanted. Couldn't have done it without you. Thanks again !
MiA
Based on your code, I've come up with this code which seems to suit my needs best
Code: Select allvar psSettingsBackup = [
["app.displayDialogs", DialogModes.NO],
["app.preferences.rulerUnits", Units.PIXELS]
];
backupRestorePSSettings();
/* Main
programing
script
comes
here */
backupRestorePSSettings();
function backupRestorePSSettings()
{
for(var i=0; i<psSettingsBackup.length; i++)
psSetArray(psSettingsBackup);
}
function psSetArray(aSettings)
{
var sOriginalValue = eval(aSettings[0]);
eval(aSettings[0]+"= "+aSettings[1]);
sNewValue = eval(aSettings[0]);
aSettings[1] = sOriginalValue;
$.writeln("[psSetArray]: "+aSettings[0]+" = "+sNewValue+" (was "+sOriginalValue+")");
}
The advantage of this method is that I have to call a single function to backup and restore settings and can define program defaults in the psSettingsBackup array.
Exactly what I wanted. Couldn't have done it without you. Thanks again !
MiA