Skip to main content
Participating Frequently
July 9, 2022
Answered

SaveOptions.DONOTSAVECHANGES doesn't work sometimes

  • July 9, 2022
  • 2 replies
  • 633 views

Hi, there is a part of my script which saves automatically color/black and white version of the file, then resized it to social media size and then adds aolumns for a square for Instagram. It ends by command

 

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

 

but sometimes the document stays opened and I have to press ctrl-w to closing it and agree closing without saving. Any idea how to prevent this?

Thnaks

{
/// ... a some layer operations are here....
turnBWLayer(true);
SaveJPG(filePath + "/big", fileName + ".jpg");
ResizeLonger(2044);

SaveJPG(filePath + "/small", fileName + "c.jpg");
turnBWLayer(true);
SaveJPG(filePath + "/small", fileName + ".jpg");

Unlock(filePath);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}

function turnBWLayer(onoff) {
    if (app.activeDocument.layers.length > 0)
    { 
        for (var i = 0; i < app.activeDocument.layers.length; i++) {
            var currentLayer = app.activeDocument.layers[i];
            if (currentLayer.name == "BW") {
                currentLayer.visible = onoff;
                return true;
            }
        }
    }
	return false;
}

// this is because another script detects an operation in progress and waits for finishing

function Lock(folder) {
var _lock = new File(folder + "/lock.txt");
_lock.open("w");
_lock.writeln(".");
_lock.close();
}

function Unlock(folder) {
var _lock = new File(folder + "/lock.txt");
_lock.remove();
}

function SaveJPG(folder, fileName)
{
jpgFile = new File(folder + "/" + fileName);
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 12;
app.activeDocument.saveAs(jpgFile, jpgSaveOptions, true,Extension.LOWERCASE);
}

 

This topic has been closed for replies.
Correct answer r-bin

This is not the complete code.

Perhaps your script does not reach this command, but stops earlier (you can put an alert() before and after closing to check). Use try{} catch(e){alert(e)} in all your functions and in code outside of functions as well.

2 replies

r-binCorrect answer
Legend
July 9, 2022

This is not the complete code.

Perhaps your script does not reach this command, but stops earlier (you can put an alert() before and after closing to check). Use try{} catch(e){alert(e)} in all your functions and in code outside of functions as well.

Participating Frequently
July 9, 2022

I had the Unlock function as the last call until today and it worked well. There must be something else.

I try to add try/catch...

Stephen Marsh
Community Expert
Community Expert
July 9, 2022

@Libb1976CZ 

 

I don't recall this issue, I doubt that the following will help, however, you could try using AM code instead of the standard object model code:

 

closeWithoutSaving();

function closeWithoutSaving() {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	descriptor.putEnumerated( s2t( "saving" ), s2t( "yesNo" ), s2t( "no" ));
	descriptor.putInteger( s2t( "documentID" ), 2037 );
	descriptor.putBoolean( s2t( "forceNotify" ), true );
	executeAction( s2t( "close" ), descriptor, DialogModes.NO );
}

 

Perhaps it has something to do with:

 

// this is because another script detects an operation in progress and waits for finishing

 

Perhaps try putting a pause in there:

 

app.refresh(); // ~1 second pause

 

or

 

$.sleep(500); // half second pause

 

Participating Frequently
July 9, 2022

Unfortunatelly, it didn't helped 😞