Skip to main content
Known Participant
January 5, 2020
Answered

make alert for top layer .. what`s the error ?

  • January 5, 2020
  • 1 reply
  • 830 views

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");
                   
                }

 

This topic has been closed for replies.
Correct answer jazz-y

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 🙂

1 reply

jazz-yCorrect answer
Legend
January 5, 2020

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 🙂