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
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 thesaveFile
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.
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’.
app.path
returns aFile
object, not a string. In your case, you most likely want the platform-specific fullpath string: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.