Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting
Moderators: Tom , Kukurykus
kenf
Posts: 3 Joined: Sun Jul 19, 2020 11:46 pm
Post
by kenf » Wed Jul 22, 2020 12:21 pm
Hello, how would I hide or automatically dismiss error alerts in this script in case layer 1 or layer 2 don't exist? Thank you.
Code: Select all
hideCheckLayers=function() {
// Hide
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var list1 = new ActionList();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "layer 1");
list1.putReference(ref1);
desc1.putList(cTID('null'), list1);
executeAction(cTID('Hd '), desc1, dialogMode);
};
// Hide
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var list1 = new ActionList();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "layer 2");
list1.putReference(ref1);
desc1.putList(cTID('null'), list1);
executeAction(cTID('Hd '), desc1, dialogMode);
};
step1(); // Hide
step2(); // Hide
};
Scriptor
Posts: 29 Joined: Tue Oct 01, 2019 12:07 pm
Post
by Scriptor » Wed Sep 23, 2020 11:04 am
Might be a bit late, but this should to the trick;
Code: Select all
hideCheckLayers=function() {
// Hide
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var list1 = new ActionList();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "layer 1");
list1.putReference(ref1);
desc1.putList(cTID('null'), list1);
executeAction(cTID('Hd '), desc1, dialogMode);
};
// Hide
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var list1 = new ActionList();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "layer 2");
list1.putReference(ref1);
desc1.putList(cTID('null'), list1);
executeAction(cTID('Hd '), desc1, dialogMode);
};
try { //Tries;
step1(); // Hide
} catch(error) { //Ignores errors
}
try { //Tries;
step2(); // Hide
} catch(error) { //Ignores errors
}
};