Skip to main content
Serg9
Known Participant
January 13, 2023
Sticky

P: jsx document.save() fails if document has no changes

  • January 13, 2023
  • 5 replies
  • 990 views

When I try to save current document with jsx, the document.save(); operation fails in case of there is no changes in the document. The error message is following: "Could not complete the Save command because of a program error".

Test code (you need to create "C:\Test\" directory first)

 

var newDoc = app.documents.add();
newDoc.saveAs(new File("C:\\test\\1.psd"));
//newDoc.artLayers.add(); //uncomment to prevent error
newDoc.save(); //will fail

 

In the previous versions of Photoshop you can call Save for any documents with or without changes without any errors.

 

Environment

  • Adobe Photoshop Version: 24.1.0 20221206.r.166 be4691b x64
  • Operating System: Windows 11 64-bit 10.0.22000.1335

 

 

This topic has been closed for replies.

5 replies

Serg9
Serg9Author
Known Participant
April 4, 2023

Looks like in 24.3.0 20230316.r.376 37b4b38 x64 thing become just worse and Save operation is completely broken now. And even the check mentioned above does not help.

 

Adobe Photoshop Version: 24.3.0 20230316.r.376 37b4b38 x64
Operating System: Windows 11 64-bit
Version: 11 or greater 10.0.22621.1413

 

Sample code

var newDoc = app.documents.add();
newDoc.saveAs(new File("C:\\test\\1.psd"));
newDoc.artLayers.add(); 
newDoc.save(); //will fails
//saveWithActionManager(newDoc.id); //will work

function saveWithActionManager(docId)
{
    var idsave = charIDToTypeID( "save" );
    var desc267 = new ActionDescriptor();
    var idDocI = charIDToTypeID("DocI");
    desc267.putInteger(idDocI, docId);
    executeAction(idsave, desc267, DialogModes.NO);
}

doc.Save fails whether there is unsaved changes or not (sample code above explicitly introduces unsaved changes before save). And the doc.saved check will not help here. The only way I get this worked is to use Action Manager-based code.

Serg9
Serg9Author
Known Participant
January 13, 2023
Yes, as a temporary fix I replaced doc.save() with

 

if(!doc.saved)
{
    doc.save();
}

 

But I still hope that we will get back the old behaviour that does not require any additional checks in this scenario.

Legend
January 13, 2023

Thanks. I've asked engineering to take a look.

Legend
January 13, 2023

This is apparently a new bug. However, you should probably not try to save files with no changes.