Copy link to clipboard
Copied
i need to make alert for top layer if his name start with 3 str ..but any active layer change alert for example this code but not working for me it`s show one alert only
if (doc.activeLayer[0]=_layers[i].name.substr(0,3) == "nav"){
alert("cool")
}else{
alert("notcool");
}
1 Correct answer
If you need to alert every time when the active layer is changed, use app.notifiers:
if (app.notifiers.length == 0) {
app.notifiersEnabled = true
app.notifiers.add('slct', File($.fileName), 'Lyr ')
} else {
if (app.activeDocument.activeLayer.name.substr(0,3) == "nav") {
alert("cool")
}else{
alert("notcool")
}
}
app.notifiers.removeAll() to disable listening events (or delete record in menu File -> Scripts -> S
...Explore related tutorials & articles
Copy link to clipboard
Copied
If you need to alert every time when the active layer is changed, use app.notifiers:
if (app.notifiers.length == 0) {
app.notifiersEnabled = true
app.notifiers.add('slct', File($.fileName), 'Lyr ')
} else {
if (app.activeDocument.activeLayer.name.substr(0,3) == "nav") {
alert("cool")
}else{
alert("notcool")
}
}
app.notifiers.removeAll() to disable listening events (or delete record in menu File -> Scripts -> Scripts event manager
if you need to check only the name of the top layer, its index is always 0, i.e.:
if (app.activeDocument.layers[0].name.substr(0,3) == "nav"){
alert("cool")
}else{
alert("notcool");
}
(not sure I understood the question correctly 🙂

