Skip to main content
Zesty_wanderlust15A7
Known Participant
July 31, 2020
Question

Can a script detect when Edit > Fade is (not) available?

  • July 31, 2020
  • 1 reply
  • 226 views

Let's say I would like a script to open the Fade dialog.

 

(1) To prevent a potential error, I would like to check if Fade is available or not.

Is this possible in a script?

 

(2) [SOLVED] When the Fade dialog opens, am I still in my script?

If so, can I catch when the user simply cancels the dialog, and can I then let the script do something (else)?

(This seems related but in case you create your own dialogs...
how-do-i-stop-running-a-script-when-i-hit-cancel-on-dialog-box  )

 

 

 

 

if (Edit>Fade is available) {
  var idFade = charIDToTypeID( "Fade" );
  executeAction( idFade, undefined, DialogModes.ALL );
}

 

 

 

Thank You for any pointers 🙂

1 reply

Inspiring
July 31, 2020

You can check if fade is available by adding some error handling and wrapping it in a function:

Caveat: only works for 1 fade.

 

fadeIsAvailable = function() {
    var ret = false;
    // Checks the history state to see if a step was added after fading.
    // If nothing was added after fading, fade wasn't available and therefore won't have been added to the history.
    
    var as = app.activeDocument.activeHistoryState;
    try{
        executeAction( charIDToTypeID( "Fade" ), undefined, DialogModes.NO );}
    catch(e){
        ret = false;
    }
    if (as != app.activeDocument.activeHistoryState) {
        ret = true;
        app.activeDocument.activeHistoryState = as;
    }
    return ret;
}


if(fadeIsAvailable()){
    alert("fade available");
} else {
    alert("fade not available");
}