playbackDisplayDialogs and objectToDescriptor

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

undavide

playbackDisplayDialogs and objectToDescriptor

Post by undavide »

Hello,
I'm working on action-recordable scripts - looking at the Fit Image example.
I've been able to successfully implement this feature, yet I've a doubt about playbackDisplayDialogs.
The Fit Image code goes as follows:

Code: Select alltry {
    //... other stuff
    var gIP = new FitImage();
    if ( DialogModes.ALL == app.playbackDisplayDialogs ) {
        gIP.CreateDialog();
        gIP.RunDialog();
    }
    else {
        gIP.InitVariables();
   ResizeTheImage(sizeInfo.width.value, sizeInfo.height.value);
    }
    if (!isCancelled) {
        SaveOffParameters(sizeInfo);
    }
}
// Lot's of things can go wrong
// Give a generic alert and see if they want the details
catch( e ) {
    if ( DialogModes.NO != app.playbackDisplayDialogs ) {
        alert( e + " : " + e.line );
    }
}

When you call the script from, say, the Automate or the Filter menu, the playbackDisplayDialogs are equal to DialogModes.ALL, while when you record the script into an action then play it, they're DialogModes.ERROR.
So I can't understand what the if DialogModes.NO in the catch is for - when are DialogModes supposed to be NO?

Another bit of code that I can't fully understand is as follows:

Code: Select allfunction SaveOffParameters(sizeInfo) {
    // save off our last run parameters
    var d = objectToDescriptor(sizeInfo, strMessage);
    app.putCustomOptions("3caa3434-cb67-11d1-bc43-0060b0a13dc4", d);
    app.playbackDisplayDialogs = DialogModes.ALL;

    // save off another copy so Photoshop can track them correctly
    var dd = objectToDescriptor(sizeInfo, strMessage);
    app.playbackParameters = dd;
}

It does:
1. save an object (sizeInfo), associating it to a string (strMessage) into an Action Descriptor;
2. save the descriptor associating it to a UUID string in the Photoshop registry;
3. set app.playbackDisplayDialogs to DialogModes.ALL
4. repeat step 2 "so Photoshop can track them correctly"
5. set the playbackParameters to the descriptor.

I can't get the why of step 4. Actually, if you delete it, it works just the same. Why do you have to save the object into a descriptor twice? What is this potential issue about Photoshop not being able "to track them correctly"?
Questions, questions...
Thanks in advance!

Davide

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

playbackDisplayDialogs and objectToDescriptor

Post by Mike Hale »

So I can't understand what the if DialogModes.NO in the catch is for - when are DialogModes supposed to be NO?
It seems that your current DialogModes is set to ERROR. However another user may have it set to NO, meaning they would rather not see any dialogs. So the test is to honor their preference.
I can't get the why of step 4. Actually, if you delete it, it works just the same.
Yes, I think with this script you could just use the descriptor that is stored in d to set the app.playbackParameters. I think the comment about tracking is really referring to the setting app.playbackParameters line, which is needed if you want the options to be recorded( tracked ) by an action.
undavide

playbackDisplayDialogs and objectToDescriptor

Post by undavide »

Thanks Mike!
I asked this ones because I've published a tutorial about action-recordable scripts that requires user input (such as Adobe's Fit Image) and I'd liked to shed some light on the dark corners.
Since you helped me twice on the subject, double thanks

Davide
(feel free to point out errors and/or imprecisions!)
Mike Hale

playbackDisplayDialogs and objectToDescriptor

Post by Mike Hale »

I think the only thing I would change is the paragraph...
That is, the GUI doesn’t pop-up when the script is called by an action – it’s the action itself that has to pass the parameters. This translates into actual code as follows:

The second column of icons in the Action panel determines whether or not a dialog shows when the action is played back. So the GUI may show when the script is called by an action.

Also I may have missed it in your example but it's important that the function return the un-localized string 'cancel' if there is an error so an action that is recording the script will know something went wrong and not store the step in the action. It should return undefined if everything went ok and the step should be recorded.
undavide

playbackDisplayDialogs and objectToDescriptor

Post by undavide »

Thanks Mike!
I agree with you about the need to specify that Action can be toggled to display dialogs.

it's important that the function return the un-localized string 'cancel' if there is an error so an action that is recording the script will know something went wrong and not store the step in the action. It should return undefined if everything went ok and the step should be recorded.

This I personally didn't know, so I'm going to add it surely!
Thanks again

Davide
undavide

playbackDisplayDialogs and objectToDescriptor

Post by undavide »

I've updated the tutorial with your suggestions (you're credited for them of course) - and added an extra section on binary export that may be helpful.
Thanks again!

Davide