skip to Main Content

I’m trying to save the activeDocument as a .psd but its returning this error

ERROR: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.

my script:

#target photoshop

var fileRef = new File(app.path.toString() + "/Samples/template.psd");
var docRef = open(fileRef);

//target text layer
var layerRef = app.activeDocument.layers.getByName("Text");

//user input
var newText = prompt("Editing " + layerRef.name, "enter new text: ");

//change contents
layerRef.textItem.contents = newText;

//save
var savePath = "/Samples/" + newText + ".psd";
var saveFile = new File(savePath);
var saveOptions = new PhotoshopSaveOptions();
saveOptions.alphaChannels = false;
saveOptions.annotations = false;
saveOptions.embedColorProfile = true;
saveOptions.layers = true;
saveOptions.spotColors = false;

app.activeDocument.saveAs(saveFile, saveOptions, true, Extension.LOWERCASE);
app.activeDocument.close();

what I want to do is basically, duplicate a template file over and over, only replacing the contents of a text layer then saving it under the string I replace in the text layer.

any tips or help is greatly appreciated.

3

Answers


  1. Chosen as BEST ANSWER

    Resolved

    I fixed my problem, by a work around. I moved both the script and the template file into the Photoshop directory and added app.path.toString() to the saveFile output variable. So it seems that the path needed to be converted to a string before saving.

    As of yet I am unsure how to work outside the Photoshop directory but for me this works so I'm happy. It's a fairly crude but I'm open to suggestion. So if anyone is having a similar issue they can use this for reference.

    #target photoshop
    
    var loop = true;
    var filePath = "/Samples/template.psd";
    
    while(loop) {
      openTemplate(filePath);
      var layerRef = app.activeDocument.layers.getByName("Text"); //target text layer
      var newText = prompt("Editing " + layerRef.name, "enter new text: "); //user input
    
      if(newText == "stop") { //stop loop by entering 'stop'
        loop = false;
      }
    
      layerRef.textItem.contents = newText;
      var savePath = app.path.toString() + "/Samples/" + newText + ".psd";
      var saveFile = new File(savePath);
      savePSD(saveFile);
      app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
    
    function openTemplate(filePath) { //open template.psd
      var fileRef = new File(app.path.toString() + filePath);
      var docRef = open(fileRef);
    }
    
    function savePSD(saveFile) { //saveas newText.psd
      var saveOptions = new PhotoshopSaveOptions();
      saveOptions.alphaChannels = false;
      saveOptions.annotations = false;
      saveOptions.embedColorProfile = true;
      saveOptions.layers = true;
      saveOptions.spotColors = false;
      app.activeDocument.saveAs(saveFile, saveOptions, true, Extension.LOWERCASE);
    }
    

  2. I suspect the problem with your original attempt is that you are not specifying a full path. I always provide a full path – even if it is just to a temporary location like ‘/c/temp/myfile.psd’.

    Login or Signup to reply.
  3. app.path returns a File object, not a string. In your case, you most likely want the platform-specific fullpath string:

    var appPath = app.path.fsName; // "C:Program FilesAdobeAdobe Photoshop 2022"
    

    Regardless if paths are correct, if you’re attempting to save anything to a directory located inside the Photoshop installation directory, you will probably need to run Photoshop as administrator.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search