photoshopphotoshop-script

How to set alert show popup just one time?


I have a script that check pathItem and show an alert if condition is wrong, but if there is more than 1 mistake, the alert will display as many time it is. I just want it show only once. How do I fix it?

Alert 1 Alert 2

#target photoshop  
    
var doc = app.activeDocument;
var pLen = doc.pathItems.length;
var pArray = [];
          
for(var i=0;i<pLen;i++){
    pArray.push(doc.pathItems[i].name)
    }
    
for(var i=0;i<pLen;i++){
    var curPath = doc.pathItems.getByName (pArray[i]);
    
        if(curPath.name == 'Freistellerpfad' && curPath.kind == "PathKind.CLIPPINGPATH") 
        {}
    else if (curPath.name == 'Ausschnitt BR' && curPath.kind == "PathKind.NORMALPATH")
        {}
    else    {alert(doc.name + '\n' + "Wrong path" + '\n' + pArray[i])}

Solution

  • I wasn't sure if that was possible, but I got it to work. The key here is displayDialogs which can be set to ALL, ERROR or NO.

    So now we need to create an error: In my example we deliberate create an error (by sampling a colour that's off the image) And then correct it.

    // Switch off any dialog boxes
    displayDialogs = DialogModes.ALL; // ON
    
    // call the source document
    var srcDoc = app.activeDocument;
    
    var x = -1;
    var y = 2;
    
    // loop over three times, only see the error once.
    for (var i = 0; i < 3; i++)
    {
      try
      {
        var pointSample = srcDoc.colorSamplers.add([x,y]);
      }
      catch (eek)
      {
        //It's going wrong
        // Switch off the dialog
        displayDialogs = DialogModes.NO; // OFF
        alert("eek"); // should see this once
        x = 2; //correct the error
      }
    }
    
    // Set Display Dialogs back to normal
    displayDialogs = DialogModes.ALL; // NORMAL
    

    Note that setting displayDialogs will affect the next script that's run. Useful for switching off if you ever have any scripts with text :D