Skip to content

Instantly share code, notes, and snippets.

@MarshySwamp
Last active January 4, 2021 00:30
Show Gist options
  • Save MarshySwamp/5db72252f9509ca26b19c97687397b68 to your computer and use it in GitHub Desktop.
Save MarshySwamp/5db72252f9509ca26b19c97687397b68 to your computer and use it in GitHub Desktop.
Code Snippet: Error Check for Open/Unsaved Doc
if (!documents.length) {
alert('There are no documents open.', 'No Document');
} else {
alert('You have a document open!');
}
// or
if (app.documents.length > 0) {
alert('You have a document open!');
} else {
alert('You must have a document open!');
}
// or
if (app.documents.length != 0) {
alert('You have a document open!');
} else {
alert('You must have a document open!');
}
// or
/* Start Open/Saved Document Error Check - Part A: Try */
savedDoc();
function savedDoc() {
try {
app.activeDocument.path;
/* Finish Open/Saved Document Error Check - Part A: Try */
/* Main Code Start */
alert("Replace this alert with your main code");
/* Main Code Finish */
}
/* Start Open/Saved Document Error Check - Part B: Catch */
catch (err) {
alert("An image must be open and saved before running this script!");
}
}
/* Finish Open/Saved Document Error Check - Part B: Catch */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment