I'm working on a script with a dialog box in photoshop. The goal is to get an End Date and Time for multiple banners.

My Cancel button works fine, but my Ok button produces a weird bug. The window appears to close, but simply disappears. Since it's a dialog, Photoshop remains frozen while waiting for the dialog to close. CMD+Tab reveals the window which I can click into. After that - the OK button does not close the window (the rest of the code inside the callback still gets called), but the Cancel button does close the window fine.

(Video showcasing the bug: https://drive.google.com/open?id=12W6J15ap52xq1jKbVPt2-XeyIxumx6Qd )

My callback functions are as follows:

var cancelled = false;
dateWin.onClose = function(){
    return cancelled;
dateBtnCancel.onClick = function(){
    cancelled = true;
    return dateWin.close();
dateBtnOK.onClick = function(){
    cancelled = false;
    return dateWin.close();


Any assistance or suggestions would be appreciated. Thank you!

UPDATE Disabling my onClose callback fixes this issue - but more importantly I don't know why this fixes the issue. Understanding what's going on here can help me not make the same mistake in the future, so if you understand why the onClose callback caused this, I would definitely appreciate the explanation.

  • Just curious, why do you need a structure like that? Where do you return your cancelled? Judging by your video you don't need that complexity Commented Dec 7, 2018 at 22:55
  • In the example above I used a boolean as the bare minimum because of a bug I was having. But sometimes I pass back an object containing a cancelled boolean along with other data from the window. The win.onClose() callback basically saving the data and returning it to the function in a convenient object. Commented Dec 7, 2018 at 23:53

1 Answer 1


I won't answer why are you exactly getting this behaviour (this is probably a question for Adobe scripting forum), however if the goal of all this to get cancelled status, I'd suggest to change the code to something like this:

var myUI = showUI();


function showUI()
    var w = new Window("dialog", "Window Name"),
        dateBtnCancel = w.add('button', undefined, 'Cancel'),
        dateBtnOK = w.add('button', undefined, 'Ok');

    dateBtnOK.onClick = function()

    var showWin = w.show();

    if (showWin == 1)
        return true
        return false

when you're cancelling/closing a dialogue window, .show() returns 2, so you can use buttons to close a window with a specific argument .close(arg) to get all the data you need. In my example I'm closing a dialogue with 1 by clicking OK button and later return true if .show() returned 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.