Last active
January 4, 2021 00:30
-
-
Save MarshySwamp/5db72252f9509ca26b19c97687397b68 to your computer and use it in GitHub Desktop.
Code Snippet: Error Check for Open/Unsaved Doc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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