Change Swatch Names Script

I need a Script to change swatch names without Error Message when it doesn't find a swatch.

I need a Script to change swatch names without Error Message when it doesn't find a swatch.
I think "try" and "catch" might be what you need. Here's an example, not changing names, but you get the idea.
var swatch;
try {
swatch = app.activeDocument.swatches.getByName("mySwatch");
} catch (error) {
// do something? or keep quiet?
}
if ( swatch != undefined) {
// do somethng with the swatch!
}
Edit: I seem to recall there might be times where Try/Catch doesn't stop Illustrator complaining. In those cases, take the time to check variables before using, eg. are they undefined, or null, to avoid the error altogether. This is probably a good practice anyway. So if you are changing names, check to see if the name is unique (or whatever your error is) before doing it.
Regards,
Mark
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.