Hello and greetings to everyone again
Thank you to this wonderful forum for providing assistance to everyone
I now have a problem
I use this code to save the psd and jpg file
I rely on Prompt to save files
But the problem here is in this step
if (val === "**") {
val = prompt("Enter New File Name to Save it First", FNtext , Namoo);
It does not accept the value saved inside a text file
But it accepts the value that is written or a fixed value between " "
For example, it accepts the value "Company banner file".
It does not accept the same value inside FNtext txt file
Why...can you help me with this?
var Filenamepath = "~/Desktop/FileName.txt";
var FNtext = readPref (Filenamepath);
var Namoo = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var Dsize = Math.round(app.activeDocument.width) + " " + Math.round(app.activeDocument.height);
var Dsize2 = Math.round(app.activeDocument.width) + " " + Math.round(app.activeDocument.height);
val = prompt("Enter New File Name to Save it First", Namoo , FNtext);
if (val === "**") {
val = prompt("Enter New File Name to Save it First", FNtext , Namoo);
app.preferences.rulerUnits = Units.CM;
app.preferences.typeUnits = TypeUnits.MM;
var saveFilePSD = File(theText + "/" + val + " " + Dsize2 + ".psd");
var saveFileJPG = File(theText + "/" + val + " " + Dsize2 + ".jpg");
while(saveFilePSD.exists || saveFileJPG.exists) {
Dsize2 += ' ';
app.preferences.rulerUnits = Units.CM;
app.preferences.typeUnits = TypeUnits.MM;
saveFilePSD = File(theText + "/" + val + " " + Dsize2 + ".psd");
saveFileJPG = File(theText + "/" + val + " " + Dsize2 + ".jpg");
}
SavePSD(saveFilePSD);
saveJPG(saveFileJPG, 11);
SaveFileName(val);
}
function readPref (thePath) {
if (File(thePath).exists == true) {
var file = File(thePath);
file.open("r", "TEXT", "????");
file.encoding= 'UTF8';
file.lineFeed = "unix";
var theText = new String;
for (var m = 0; m < file.length; m ++) {
theText = theText.concat(file.readch());
};
file.close();
return String(theText)
}}
function SaveCurrentConfig(cInfo, ConfigFile){
var F = new File(ConfigFile);
F.open("w", "TEXT", "????");
F.encoding = "UTF8";
F.writeln(cInfo);
F.close();
}
function SaveFileName(val){
var ConfigFile = "~/Desktop/FileName.txt";
var cInfo = "";
cInfo = val
SaveCurrentConfig(cInfo, ConfigFile)
}
function SavePSD(saveFile){
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
psdSaveOptions.layers = true;
activeDocument.saveAs(saveFile, psdSaveOptions, false, Extension.LOWERCASE);
}
function saveJPG(saveFile, jpegQuality) {
var jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
//app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}