3 Replies Latest reply on Jan 3, 2018 12:09 PM by littlehorse3

    Access to document windows, tabs

    littlehorse3 Level 1

      I opened document by script, then I select by script menu item: Window->Arrange->New window for <document>.

      And I see 2 tabs/windows of the same document. I didn't find how I can calculate or close this windows/tabs by script.

      I found only that I can manipulate with documents but app.documents.length is still one. If I call app.activedocument.close It will close 2 tabs

      Didi anybody resolve such problem?

        • 2. Re: Access to document windows, tabs
          Kukurykus Adobe Community Professional

          Save it as "Window to Right.jsx":

           

          function arng() {
               i = (len = (a = arguments).length) - len; while(i < len) {
                    function sTT(v) {return stringIDToTypeID(v)} (ref1 = new ActionReference())
                    .putEnumerated(sTT('menuItemClass'), sTT('menuItemType'), sTT(a[i++]));
                    (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1),
                    executeAction(sTT('select'), dsc1, DialogModes.NO)
               }
          }
          
          documents.add(), arng('newView', 'tile'), File($.fileName.slice(0, -3) + 'exe').execute()
          

           

          Save it as "Window to Right.exe":

           

          WinGet wins, List
               Loop, % wins {
               id := "ahk_id "wins%A_Index%
               d := "OWL.DocumentWindow"
               WinGetClass c1, % id
               if (c1 = d) {
                    if (i) {
                         WinKill % id
                         break
                    }
                    i++
               }
          }
          

           

          'Window to Right' in file name must be common for .jsx and .exe as $.fileName executes .exe that is in the same folder as .jsx

          Copy them to your Presets folder of your Photoshop and after relaunching choose from File / Scripts 'Window to Right' item.

          JS will create new document, make new window/tab for this document and arrange both vertically (1st to left, 2nd to right).

           

          Finally it executes autohokey.com script. It is compiled from .ahk to .exe format, so there is no need for you to download AHK, as far as you're not going to edit that script I wrote. That it does is making loop over all current (not only Ps) windows and when first Photoshop document (new tab created) is found it skips it to close another one (previously opened as first).

           

          It's very good way if you want your docs were opened on the right side of screen (via applied script) due to preferences of some users, not on the left like it's by default in case on single document. However when your intention is to open 2 docs but strictly 1st as first and 2nd as 2nd to have first on right and second on left part of screen you probably can't do it easly with only Photoshop. You have start a process which between both documents openings will make a new window for 1st one to "tile these 'twins' vertically", run ahk script and open second document to make vertical arrangement once again.

           

          I'm attaching 'Window to Right.exe' if you don't want to install autohotkey language: Dropbox - Window to Right.exe

           

          Important: if you'd like to continue .jsx with some more code then .exe will not have effect. To change it there must be additional code line at end of .exe (after its ran by .jsx) which will run .jsx again. If so current .jsx script must have other constraction than now, ie. be divided into conditional segments. So have a scheme like it:

           

          if (there are not opened documents) {
               play those 10 lines I wrote
          }
          
          else {
               continue your part of code...
          }
          

           

           

          Actually for practise as I'm still novice into Autohotkey I created program for that I just described as well as rewrote .jsx part:

           

          #target photoshop
          function arng() {
               i = (len = (a = arguments).length) - len; while(i < len) {
                    function sTT(v) {return stringIDToTypeID(v)} (ref1 = new ActionReference())
                    .putEnumerated(sTT('menuItemClass'), sTT('menuItemType'), sTT(a[i++]));
                    (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1),
                    executeAction(sTT('select'), dsc1, DialogModes.NO)
               }
          }
          
          if (!documents.length) {
               documents.add(), arng('newView', 'tile'),
               File($.fileName.slice(0, -3) + 'exe').execute()
          }
          
          else {
               alrt = 'There\'s only one document on the'
               alrt += ' right side of screen!', alert(alrt)
          }
          

           

          Not updated to DropBox, so download AHK, paste it to editor, save, then right click on file in Windows and choose 'Compile'.

           

          rnm := RegExReplace(A_ScriptFullPath, "exe$", "jsx")
          while t1 != txt := "Script Alert" {
               WinGet wins, List
               Loop, % wins {
                    id := "ahk_id "wins%A_Index%
                    d := "OWL.DocumentWindow"
                    WinGetClass c1, % id
                    if sA {
                         WinGetTitle t1, % id
                         if (t1 = txt) {
                              send {Enter}
                              break
                         }
                         if A_TickCount - tme > 1000 {
                              t1 := txt
                              break
                         }
                    }
                    else if (c1 = d && !sA) {
                         if i {
                              tme := A_TickCount
                              WinKill % id
                              run % rnm
                              sA = 1
                              break
                         }
                         i++
                    }
               }
          }
          
          • 3. Re: Access to document windows, tabs
            littlehorse3 Level 1

            Thanks for your answer but AHK is not good solution for me because I need MacOS support