• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

Problem saving the file via Prompt

Enthusiast ,
May 19, 2024 May 19, 2024

Copy link to clipboard

Copied

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);
                    }          
TOPICS
Actions and scripting

Views

165

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , May 19, 2024 May 19, 2024

Replace

F.writeln(cInfo);

with

F.write(cInfo);

Votes

Translate

Translate
Adobe
People's Champ ,
May 19, 2024 May 19, 2024

Copy link to clipboard

Copied

What is theText found in this line, for example?

var saveFilePSD = File(theText + "/" + val + " " + Dsize2 + ".psd");

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 19, 2024 May 19, 2024

Copy link to clipboard

Copied

@r-bin 
the text is the path to save file

var thePref = "~/Desktop/SavePath.txt";
var theText = readPref (thePref);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 19, 2024 May 19, 2024

Copy link to clipboard

Copied

Your code doesn't match what you show.

Show the complete script code and the contents of the text file and its file name.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 19, 2024 May 19, 2024

Copy link to clipboard

Copied

@r-bin 
Very great, here is the complete code
- first Create a text file on your desktop called SavePath.txt with the save path to which you want to save the files.
- second creat a text file on your desktop called FileName.txt with value " any name are you want " to use it for FNtext  for prompt next

Try the code and you will notice that it does not save files using data inside FNtext


var thePref = "~/Desktop/SavePath.txt";
var theText = readPref (thePref);

var Filenamepath = "~/Desktop/FileName.txt";
var FNtext = readPref (Filenamepath);

var Namoo = app.activeDocument.name.replace(/\.[^\.]+$/, '');
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);
                    }        

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 19, 2024 May 19, 2024

Copy link to clipboard

Copied

Replace

F.writeln(cInfo);

with

F.write(cInfo);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 19, 2024 May 19, 2024

Copy link to clipboard

Copied

LATEST

@r-bin 
very nice, thank you for helping me

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines