Photoshopスクリプトのドキュメントが開いているか判定する方法です。
if (app.documents.length === 0) { alert("ドキュメントが開いていません。", "エラー", true); }