New document loses focus when dialog window is closed

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

cbourn

New document loses focus when dialog window is closed

Post by cbourn »

After adding a new document to Photoshop via a dialog window the document loses focus. I have already tried bringToFront() and app.refresh().

Notice that the document remains in focus UNTIL the dialog closes (test by removing win.close()).

Output of app.activeDocument is correct, but the document isn't in focus.

Code: Select allwin = new Window('dialog');
    win.btnAdd = win.add('button');
    win.btnAdd.text = 'Add new document';
    win.btnAdd.onClick = function() {
        win.close();
        app.documents.add('8 in', '10 in', 300, '8x10');
    };
win.center();
win.show();
pfaffenbichler

New document loses focus when dialog window is closed

Post by pfaffenbichler »

Have you tried creating a variable for the last created document and using
Code: Select allapp.activeDocument = …
after the window has been closed (with some check to make sure a file has been created)?
cbourn

New document loses focus when dialog window is closed

Post by cbourn »

Code: Select allalert(app.activeDocument.name) outputs the correct document name and I have tried redefining app.activeDocument with a reference to the new document. The documents is active, just not in focus.

It appears that the Photoshop application gains focus (because the minimize/maximize/close buttons are enabled) while the document loses focus (because the minimize/maximize/close buttons are disabled).



Note: if there is another document already open the new document is added behind the other document.

Update: Using Mac OSX 10.10, Photoshop CC & Photoshop CS6, this may only be a Mac OSX issue
pfaffenbichler

New document loses focus when dialog window is closed

Post by pfaffenbichler »

I suppose this is bad form, but it seems to work.
Code: Select allvar theDoc;
win = new Window('dialog');
    win.btnAdd = win.add('button');
    win.btnAdd.text = 'Add new document';
    win.btnAdd.onClick = function() {
        win.close();
        theDoc = app.documents.add('8 in', '10 in', 300, '8x10');
    };
win.center();
var myReturn = win.show();
try {
   app.activeDocument = theDoc;
   }
catch (e) {};
cbourn

New document loses focus when dialog window is closed

Post by cbourn »

Sincerest thanks for attempting to help with this, but that doesn't fix it. The application and document look exactly as shown in the image above.

The application is in focus, yet the document is NOT.
Mikaeru

New document loses focus when dialog window is closed

Post by Mikaeru »

Maybe you should try to delay the creation of the new document right *after* the dialog is closed:

Code: Select allvar addDocument = false;
var win = new Window ('dialog');
win.btnAdd = win.add ('button', undefined, 'Add new document');
win.btnAdd.onClick = function () { addDocument = true; win.close (); };
win.center ();
win.show ();
if (addDocument)
{
    app.documents.add ('8 in', '10 in', 300, '8x10');
}

HTH...
cbourn

New document loses focus when dialog window is closed

Post by cbourn »

SOLVED. That's it! Such a simple and elegant solution. Thank you!