SaveOptions.DONOTSAVECHANGES doesn't work sometimes

Community Beginner ,
Jul 09, 2022 Jul 09, 2022

Copy link to clipboard

Copied

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);
}

 

TOPICS
Actions and scripting

Views

60

Likes

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

Adobe Community Professional , Jul 09, 2022 Jul 09, 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.

Likes

Translate

Translate
Adobe Community Professional ,
Jul 09, 2022 Jul 09, 2022

Copy link to clipboard

Copied

@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

 

Likes

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
Community Beginner ,
Jul 09, 2022 Jul 09, 2022

Copy link to clipboard

Copied

Unfortunatelly, it didn't helped 😞

Likes

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
Adobe Community Professional ,
Jul 09, 2022 Jul 09, 2022

Copy link to clipboard

Copied

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.

Likes

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
Community Beginner ,
Jul 09, 2022 Jul 09, 2022

Copy link to clipboard

Copied

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...

Likes

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
Community Beginner ,
Jul 09, 2022 Jul 09, 2022

Copy link to clipboard

Copied

LATEST

My apology. I investigated an old version of the script. The new which is really called has a condition which handles not closing the file it if hasn't beed saved yet. But the evaluating was wrong...

Likes

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