Retsied
Retsied

Reputation: 93

Python - Close all active documents without saving

I need to close all Photoshop documents, be it any number, without saving and without any user prompt. My current code is below for closing the active document only.

psApp = win32com.client.Dispatch("Photoshop.Application")
psApp.Application.ActiveDocument.Close(2) # close file without saving
psApp.Quit()

Photoshops API documentation is terrible, but here's what I've attempted for closing all:

while psApp.documents.length:
    psApp.activeDocument.close()

AttributeError: <unknown>.length

Any help is very much appreciated!

Upvotes: 1

Views: 1364

Answers (2)

Yasuaki
Yasuaki

Reputation: 1

I can close all active documents with this.

while psApp.Documents.Count > 0:
    psApp.ActiveDocument.Close(2)

Upvotes: 0

tst
tst

Reputation: 381

Try this:

while True:
    try:
        psApp.Application.ActiveDocument.Close(2)
    except:
        break
psApp.Quit()

I dont have PS, but I can confirm it works with Word!

Upvotes: 3

Related Questions