Can't close a document using document.close!

,

Hello everyone,

I’m not sure why can’t I make document.close or document.closeWithoutSaving; to work. I think it is a simple enough command. I’m using photoshop 24.1 and working on a plugin. try-catch block did not detect any errors.

Thank you for your help

Maybe post your code so we can help you identify the problem.

I’m simply trying to open two documents and then closing one of them, I’m doing more stuff, but I tried this code alone, and still, it is not working.

async function main() {
    const app = require('photoshop').app;
    let imgDocuments = await openDocs();
    await close();
    async function openDocs() {
        try {
            let imgDocuments = [];

            do {
                let entry = await require('uxp').storage.localFileSystem.getFileForOpening()
                const imgDocument = await app.open(entry);
                imgDocuments.push(imgDocument)
            } while (imgDocuments.length < 2)
            return imgDocuments;
        }
        catch (er) { console.log(er) }
    }

    async function close() {
        app.showAlert(app.documents[1].name); //this is for verification
        app.documents[1].closeWithoutSaving;
    }
}
async function generatePhoto() {
    await require("photoshop").core.executeAsModal(main, { "commandName": "Action Commands" });
}

module.exports = {
    generatePhoto
}

It looks like you aren’t calling it with () after the method name

Try app.documents[1].closeWithoutSaving(); in the close function. Tested on my machine and it closes with no issues. If you still face errors, it may have to do with some other logic you’re using.

Yes, the () was the issue, That was embarrassing :flushed: . However, I can blame the VS code IntelliSense and also I wish the error reporting was more robust.

In this case there’s nothing to report. There was no error. You were simply not calling a function when you actually wanted to :slightly_smiling_face:

1 Like