Try this:
#target photoshop
var colorFile = new File('~/desktop/colorFile.txt');
var cInfo
var dlg = new Window('dialog','Save Foreground Color');
var saveC = dlg.add('button',undefined,'Save Foreground Color');
var getC = dlg.add('button',undefined,'Retrieve Foreground Color');
colorFile.exists?getC.enabled = true:getC.enabled = false;
saveC.onClick = function(){
var fC = new SolidColor();
fC = foregroundColor;
cInfo = fC.rgb.red +','+fC.rgb.green +','+fC.rgb.blue;
writeFile (colorFile, cInfo)
dlg.close();
}
getC.onClick = function(){
var cTxt = readFile (colorFile);
var fC = new SolidColor();
fC.rgb.red = cTxt.split(',')[0];
fC.rgb.green = cTxt.split(',')[1];
fC.rgb.blue = cTxt.split(',')[2];
foregroundColor=fC;
dlg.close();
}
dlg.show();
//===============READ/WRITE functions========================================
//=========================================================================
function readFile(file) {
if (!file.exists) {
alert( "Cannot find file: " + deodeURI(file.absoluteURI));
}
else{
file.encoding = "UTF8";
file.lineFeed = "unix";
file.open("r", "TEXT", "????");
var str = file.read();
file.close();
return str;
};
};
function writeFile(file,str) {
file.encoding = "UTF8";
file.open("w", "TEXT", "????");
//unicode signature, this is UTF16 but will convert to UTF8 "EF BB BF"
file.write("\uFEFF");
file.lineFeed = "unix";
file.write(str);
file.close();
};
//=========================================================================