26 Replies Latest reply on Aug 17, 2008 5:17 AM by sstanleyau

    OpenDialog to a specific folder

    Loic.Aigon Adobe Community Professional
      Hi,
      I saw this question was discussed already but following the tip, I don't have any success. Moreover I couldn't post in the thread so I have to open this topic. Sorry about that.

      Well,
      here is the matter :
      var myfile = File("\\192.168.1.1\Marketing\17. Produits\COPY\Tiff_CMYK_300dpi\ok\copyripok_uk.tif");
      myfile.openDialog(); // > ERROR

      /*

      File.openDialog() // Works great.

      */

      So it's so annoying. Where am I wrong ?
      Thanks for help
      Loic
        • 1. Re: OpenDialog to a specific folder
          Level 1
          myFile.openDlg();

          Bob
          • 2. Re: OpenDialog to a specific folder
            Loic.Aigon Adobe Community Professional
            Hi Bob
            Thanks for taking the time to answer.
            Unfortunately, I am still stuck. I get a null info when trying this.
            It's like Indesign tried to open the dialog (the app seems to vibrate) but nothing appears at the end and the javascript console says null.
            Loic
            • 3. Re: OpenDialog to a specific folder
              Loic.Aigon Adobe Community Professional
              Hi,
              some news,
              I get a result if the file is placed on my hard drive ("c:/...") but it still fails when the file is on a server ("\\192.168.1.1\...").
              Is there any way to solve this ?
              Loic
              • 4. Re: OpenDialog to a specific folder
                Level 1
                Exactly.

                The File object doesn't play all that well with servers unless the drive is mounted. That hasn't been a requirement for me, so I don't know if you can do that without mounting the server drive or not.

                myFile.exists will tell you if you've managed to point to the server correctly.

                Bob
                • 5. Re: OpenDialog to a specific folder
                  Loic.Aigon Adobe Community Professional
                  Ok thanks for all your advices.
                  I guess I will have to try replacing the complete data (\\192.168...) by a shorter version (i.e. for example g:/...).
                  I ll keep you in touch.
                  Loic
                  • 6. Re: OpenDialog to a specific folder
                    Hi Loic/Bob,

                    Using openDlg, is there a parameter to select multiple files?

                    Regards
                    Norbert
                    • 7. Re: OpenDialog to a specific folder
                      Loic.Aigon Adobe Community Professional
                      File.openDialog (prompt, filter, multiSelect)
                      so
                      File.openDialog ("Pick me...", undefined, true) //Undefined when the parameter is not required.
                      Hope it helps
                      • 8. Re: OpenDialog to a specific folder
                        Level 1
                        If you want to Filter files, and you want your script to work on either platform, then you need to use platform-specific code, along these lines:
                        (function() {
                        

                          var myFile = getDocFile();
                          if (myFile == null) return;
                          alert(myFile.creator + " " + myFile.type);

                          function getDocFile() {
                            // cross-platform document file selector
                            if (File.fs == "Windows") {
                              var select = "InDesign documents:*.INDD"
                            } else {
                              var select = filterFiles
                            }
                            myFile = File.openDialog("Choose an InDesign document:", select);
                            return myFile;
                            function filterFiles(file) {
                              while (file.alias) {
                                file = file.resolve();
                                if (file == null) { return false }
                              }
                              if (file.constructor.name == "Folder") return true
                              var extn = file.name.toLowerCase().slice(file.name.lastIndexOf("."));
                              switch (extn) {
                                case ".indd" : return true;
                                default : return false
                              }
                            }
                          }
                        }())
                        If you've not seen an anonymous function before, don't be put off. Wrapping a script in an anonymous function protects the global name space.

                        Notice the filtering mechanism. Windows users have it easy. Just get that string right and Windows does the whole job for you (although if you look across a network to a Mac disk that has aliases on it, Windows won't be able to service those for you).

                        Mac users have to deal with aliases (that's what the while loop is about -- resolving until it either finds a file or a broken alias). Then keeping folders active.

                        This particular code doesn't work if you have files on your Mac disks that lack extensions, but that's so 20th Century.

                        The most common mistake Windows users make (or, to be more honest, I make when I'm doing the Windows string) is to forget the prefix. If you hand Windows a string like: "*.EPS, *.TIF" you'll get the wrong File dialog and the one you get is much harder to work with. You need something like: "Graphics files: *.EPS, *TIF".

                        In this example, I've used the filter with openDialog, but the same approach can be used with openDlg (which takes the same three arguments -- albeit, I've only used the first two in this example).

                        Dave
                        • 9. Re: OpenDialog to a specific folder
                          Level 1
                          One odd thing about the Mac side is that no matter what you do, application files are always active, but they're treated as files, not folders, so you can't see into a product package. It's hard to tell if this is deliberate or accidental behavior. It just is.

                          I'm not sure what happens if you use openDlg with a File that is inside a package -- that might work. I haven't tried it.

                          Dave
                          • 10. Re: OpenDialog to a specific folder
                            Hi Loic and Dave,

                            Thanks for your responses. Filtering files is not an issue.

                            Loic. I tried adding a third parameter heres the code

                            myDocs = File(myFolder+"/"+myMask)
                            myFile=myDocs.openDlg("Select Files To Open", myFolder+"/"+myMask.indd, true);
                            app.open(myFile)

                            This doesn't work

                            Regards
                            Norbert
                            • 11. Re: OpenDialog to a specific folder
                              Loic.Aigon Adobe Community Professional
                              Hi,
                              I would say that's because your filter parameter is not as expected.
                              It should be something like "Files : *.indd".
                              The filter will only exclude file types that are not the one expected.
                              So if you want to open a specific file on your hard drive you have to say
                              app.open(File(mypath)) //mypath is the path to the file
                              or if you want a indd file in a folder in a more generic way
                              you say
                              FIle.openDialog("Pick me","Files : *.indd", true);
                              hope it helps
                              Loic

                              PS : Hey folks, saying that I noticed on my mac that the filter seems to be ignored meanwhile on my pc at work it's taken in account ? Is that something normal ?
                              • 12. Re: OpenDialog to a specific folder
                                Level 1
                                Loic,

                                Did you see my message a few back? It explains the differences between Mac and Windows filters and provides cross-platform code for handing it.

                                Dave
                                • 13. Re: OpenDialog to a specific folder
                                  Loic.Aigon Adobe Community Professional
                                  Hi Dave,
                                  Sorry to make you post again. I read quickly you former post and it's true I should have been more attentive to it. Ok I got the idea now.
                                  Thanks a lot for your post and precisions !
                                  Loic
                                  • 14. Re: OpenDialog to a specific folder
                                    Hi Loic,

                                    Sorry I have not made myself clear.

                                    I should have mentioned that I am using openDlg on WIN JS CS2.

                                    What I am hoping to achive is to multi-select files in a particular folder.

                                    myFile=myDocs.openDlg("Select Files To Open", myFolder+"/"+myMask, true);

                                    The aboove line works right upto displaying all require files in the particular folder but I cannot multi select.

                                    Regards
                                    Norbert
                                    • 15. Re: OpenDialog to a specific folder
                                      Level 1
                                      myFolder + "/" myMask

                                      Does not look like the right syntax for a filter.

                                      We've been trying to tell you that for a few messages now.

                                      Dave
                                      • 16. Re: OpenDialog to a specific folder
                                        Hi Dave:

                                        Re: We've been trying to tell you that for a few messages now.

                                        I've seen yours and Loic post saying to use Files: *.indd as a filter

                                        But like I mentioned filtering is not the issue.

                                        Using myFolder+"/"+myMask, works perfectly in filtering the files that I need displayed (And what I am hoping to acvhive)

                                        What I cannot manage to achieve is the select multiples files i.e: The third parameter in openDlg.

                                        Thanks so much for responding.

                                        Sincerely appreciate this.

                                        Regards
                                        Norbert
                                        • 17. Re: OpenDialog to a specific folder
                                          Hi Dave,

                                          I just tried the code on CS3 and it allows me to select multiple files.

                                          So I am guessing that the code does not work for CS2 to multi select.

                                          However, in CS2's user interface when I do a File---> Open, it allows me to do a multi select.

                                          Any suggestions?

                                          Regards
                                          Norbert
                                          • 18. Re: OpenDialog to a specific folder
                                            Loic.Aigon Adobe Community Professional
                                            Have a look on page 540 of the Indesign CS2 scripting reference :
                                            openDialog
                                            File.openDialog
                                            ([prompt][,select])
                                            prompt
                                            Optional. A string containing the prompt text, if the dialog allows a prompt.
                                            select
                                            Optional. A file or files to be preselected when the dialog opens:
                                            In Windows, a string containing a comma-separated list of file types with descriptive
                                            text, to be displayed in the bottom of the dialog as a drop-down list from which the user can select which types of files to display.
                                            Each element starts with the descriptive text, followed by a colon and the file search masks for this text, separated by semicolons. For example, to display two choices, one labeled Text Files that allows selection of text files with extensions .TXT and .DOC, and the other labeled All files that allows selection of all files:
                                            Text Files:*.TXT;*.DOC,All files:*
                                            So it seems CS2 won't set capacity to allow multiple selecting files
                                            So you have to use a workaround.
                                            Folder.getFiles() with a indd selection could do the trick but it implies that it will get ALL the files available and not the one the user may only want...
                                            BUT you know what ? Why don't you just giv a try and maybe in CS2 multi opening will be allowed with the File.openDialog method without any need to set anything ?
                                            For more precise informations, I give my place to specialists :-)
                                            • 19. Re: OpenDialog to a specific folder
                                              Hi Loic,

                                              You are right. Page 540 of the CS2 scripting guide does say:

                                              "A file or files to be preselected when the dialog opens:"

                                              However myFile=File.openDialog("Pick me","Files : *.indd", true);

                                              Doesn't aqllow multiple selections.

                                              So is the CS2 Scripting guide wrong or am I doing something wrong?

                                              Regards
                                              Norbert
                                              • 20. Re: OpenDialog to a specific folder
                                                Loic.Aigon Adobe Community Professional
                                                Well effectively the formulation of the explanation let think that you can select multiple files but the command doesn't.
                                                Weird, either the explanation is false, either we misunderstood a point.
                                                Olav will be welcome to clear that stuff !
                                                • 21. Re: OpenDialog to a specific folder
                                                  How does one get in touch with Olav to rea a particlar thread? Or does he read all thats posted here??
                                                  • 22. Re: OpenDialog to a specific folder
                                                    Loic.Aigon Adobe Community Professional
                                                    okvern at adobe.com at the last resort :-)
                                                    • 23. Re: OpenDialog to a specific folder
                                                      Hi Loic,

                                                      I normally don't send private emails regarding forum posts but maybe this time I will.

                                                      However, what other options do I have before I email Olav?

                                                      Regards
                                                      Norbert
                                                      • 24. Re: OpenDialog to a specific folder
                                                        Loic.Aigon Adobe Community Professional
                                                        What about posting a new topic called "CS2 openDialog problem" ?
                                                        It's true that if Olav can answer to your problem, it's better that anyone can enjoy it.
                                                        Loic
                                                        • 25. Re: OpenDialog to a specific folder
                                                          Level 1
                                                          I've just realized why it is not at all odd that (as I said in message 9) "...no matter what you do, application files are always active..."

                                                          The reason is that they are returned to ExtendScript as folders, not files, so my previous code that explicitly tested for files with a .app extension was on the right track but in the wrong place. If you want to exclude applications, you need to add logic to the folder detection code, returning false if the folder name ends in .app.

                                                          You can check this by running:

                                                          #target indesign
                                                          alert(app.fullName.constructor.name)

                                                          It displays an alert that says Folder.

                                                          Dave
                                                          • 26. Re: OpenDialog to a specific folder
                                                            sstanleyau Level 4
                                                            On 17/8/08 11:02 PM, "Dave Saunders" <member@adobeforums.com> wrote:<br /><br />> they are returned to ExtendScript as folders, not files<br /><br />Presumably only if they are packaged as bundles; these days that's pretty<br />much all apps, but older ones might not be. And some "files" are also<br />packages and therefore presumably returned as folders, although they're much<br />rarer.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>